Search copy row improvement.

Clayraw

New Member
Joined
Mar 6, 2015
Messages
6
Hi all,

I have been doing some coding and got a fair bit working. Now I use a "search copy entire row" macro which works fine for 1 sheet, but I want to apply this coding to other (3 sheets) as well without having to retype the lookup string into the inputbox. The lookup column stays the same and is located in column A on each sheet. Till now I didn't manage to get it working, it seems it doesn't see "Strtofind" as a string, at least, just for the first sheet. Please do not hesitate if you have any further improvements.


Code:
 'Find copy row'
    Dim strLastRow As String
    Dim rngC As Range
    Dim Strtofind As String, FirstAddress As String
    Dim wSht2 As Worksheet
    Dim wSht1 As Worksheet
    Dim rngtest As String
    Application.ScreenUpdating = False

    'Define workbooks - vendor and macro file'
    Dim wb1 As Excel.Workbook
    Set wb1 = Workbooks("Template required information from VENDOR NEW -product category management.xlsx")
    Dim wb2 As Excel.Workbook
    Set wb2 = Workbooks("Macro file 2.xlsm")
    
    'Define worksheets names'
    Set wSht2 = wb2.Sheets("Sheet2")
    Set wSht4 = wb2.Sheets("Sheet3")
    Set wSht6 = wb2.Sheets("Sheet4")
    Set wSht8 = wb2.Sheets("Sheet5")
    Set wSht1 = wb1.Sheets(" 3. MANDATORY ERP DATA")
    Set wSht3 = wb1.Sheets("5. DESCRIPTIONS")
    Set wSht5 = wb1.Sheets("4. AVAILABILITY PER COUNTRY")
    Set wSht7 = wb1.Sheets("6. ASSETS")
    
    'Define lookup range & paste sheet ERP'
     Strtofind = InputBox("Enter manufacturer part no.", "Copy rows to Group/Measure file")
        With wSht1.Range("A2:A5000")
            Set rngC = .Find(What:=Strtofind, LookAt:=xlWhole)
            If Not rngC Is Nothing Then
                FirstAddress = rngC.Address
                    Do
                    strLastRow = wSht2.Range("A" & Rows.Count).End(xlUp).Row + 1
                    rngC.EntireRow.Copy wSht2.cells(strLastRow, 1)
                    Set rngC = .FindNext(rngC)
                Loop While Not rngC Is Nothing And rngC.Address <> FirstAddress
            End If
    End With
    
    'Define lookup range & paste sheet DESCRIPTIONS'
        With wSht3.Range("A2:A5000")
            Set rngC = .Find(What:=Strtofind, LookAt:=xlWhole)
            If Not rngC Is Nothing Then
                FirstAddress = rngC.Address
                    Do
                    strLastRow = wSht4.Range("A" & Rows.Count).End(xlUp).Row + 1
                    rngC.EntireRow.Copy wSht2.cells(strLastRow, 1)
                    Set rngC = .FindNext(rngC)
                Loop While Not rngC Is Nothing And rngC.Address <> FirstAddress
            End If
    End With
    
    'Define lookup range & paste sheet AVAILABILITY'
        With wSht5.Range("A2:A5000")
            Set rngC = .Find(What:=Strtofind, LookAt:=xlWhole)
            If Not rngC Is Nothing Then
                FirstAddress = rngC.Address
                    Do
                    strLastRow = wSht6.Range("A" & Rows.Count).End(xlUp).Row + 1
                    rngC.EntireRow.Copy wSht2.cells(strLastRow, 1)
                    Set rngC = .FindNext(rngC)
                Loop While Not rngC Is Nothing And rngC.Address <> FirstAddress
            End If
    End With
    
     'Define lookup range & paste sheet ASSETS'
        With wSht7.Range("A2:A5000")
            Set rngC = .Find(What:=Strtofind, LookAt:=xlWhole)
            If Not rngC Is Nothing Then
                FirstAddress = rngC.Address
                    Do
                    strLastRow = wSht8.Range("A" & Rows.Count).End(xlUp).Row + 1
                    rngC.EntireRow.Copy wSht2.cells(strLastRow, 1)
                    Set rngC = .FindNext(rngC)
                Loop While Not rngC Is Nothing And rngC.Address <> FirstAddress
            End If
    End With

Many thanks in advance.

Clayraw
 
Last edited:

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.

Forum statistics

Threads
1,224,521
Messages
6,179,291
Members
452,902
Latest member
Knuddeluff

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top