+ Reply to Thread
Results 1 to 5 of 5

Failing to write a search and cut and paste macro

Hybrid View

top_dog Failing to write a search and... 03-17-2014, 03:08 AM
nilem Re: Failing to write a search... 03-17-2014, 03:28 AM
top_dog Re: Failing to write a search... 03-17-2014, 04:17 AM
nilem Re: Failing to write a search... 03-17-2014, 04:35 AM
top_dog Re: Failing to write a search... 03-17-2014, 04:50 AM
  1. #1
    Registered User
    Join Date
    02-25-2014
    Location
    Auzzie
    MS-Off Ver
    Office 365
    Posts
    57

    Failing to write a search and cut and paste macro

    I have successfully wrote a few Macros from reading the information on this forum. This one has got me beat after 3 days trying to figure it out, can someone please help me otherwise I might smash my laptop

    What I am trying to do is search for an identifying code and then cut in paste it into its own sheet. The macro needs to be able to grow and shrink as some weeks there might be 7 of them item and next 5, also sometimes there will be no data for that code. I think I have wrote a code that is pretty close but I am missing something

     For nidx = 0 To UBound(storeNos)
            Cells.Find(What:=storeNos(nidx), After:=ActiveCell, LookIn:=xlValues, LookAt:= _
            xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:= _
                True, SearchFormat:=True).Activate
    Help will be much appreciated as I can then move on with my life lol
    Attached Files Attached Files
    Last edited by top_dog; 03-17-2014 at 04:52 AM. Reason: Pls use code tags around your codes.

  2. #2
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Failing to write a search and cut and paste macro

    Hi top_dog,
    try it
    Sub ertert()
    Dim s$, r
    Application.ScreenUpdating = False
    With Sheets("Data").Range("A1").CurrentRegion
        .Parent.AutoFilterMode = False: s = "~"
        For Each r In .Offset(1).Resize(.Rows.Count - 1).Columns(2).Value
            If InStr(s, "~" & r & "~") = 0 Then
                If Not Evaluate("ISREF('" & r & "'!A1)") Then
                    Sheets.Add(after:=Sheets(Sheets.Count)).Name = r
                Else
                    Sheets(r).UsedRange.ClearContents
                End If
                .AutoFilter 2, r
                .Copy Sheets(r).Range("A1")
                s = s & r & "~"
            End If
        Next
        .AutoFilter
    End With: Application.ScreenUpdating = True
    End Sub

  3. #3
    Registered User
    Join Date
    02-25-2014
    Location
    Auzzie
    MS-Off Ver
    Office 365
    Posts
    57

    Re: Failing to write a search and cut and paste macro

    Man you did that so quick! Is there anyway to make it not make new tabs and use the ones I have already?

    Many Thanks nilem, you have saved me so much headache.

  4. #4
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Failing to write a search and cut and paste macro

    try
    Sub ertert()
    Dim arr, i&
    Application.ScreenUpdating = False
    arr = Array("Ap", "Apple", "Ba", "Banana", "Pe", "Pear")
    With Sheets("Data").Range("A1").CurrentRegion
        .Parent.AutoFilterMode = False
        For i = 0 To UBound(arr) Step 2
            .AutoFilter 2, arr(i)
    '        Sheets(arr(i + 1)).UsedRange.ClearContents 'uncomment if needed
            .Copy Sheets(arr(i + 1)).Range("A1")
        Next i
        .AutoFilter
    End With: Application.ScreenUpdating = True
    End Sub

  5. #5
    Registered User
    Join Date
    02-25-2014
    Location
    Auzzie
    MS-Off Ver
    Office 365
    Posts
    57

    Re: Failing to write a search and cut and paste macro

    Yep thats it, wow I was way off! You just saved me heaps of time!

    Thanks again I am really grateful for you help

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] paste.special is failing
    By Barking_Mad in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-05-2014, 08:03 AM
  2. [SOLVED] How to write Macro that could cut and paste data
    By ims0phie in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-06-2013, 11:34 AM
  3. Replies: 2
    Last Post: 02-17-2012, 03:08 AM
  4. Search or lookup function... attempting and failing
    By jhubbzwhat in forum Excel General
    Replies: 4
    Last Post: 10-15-2008, 11:03 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1