Search multiple worksheets and fetch column values conditionally

sofas

Active Member
Joined
Sep 11, 2022
Messages
469
Office Version
  1. 2019
Platform
  1. Windows
Welcome. Can you help me get a code that enables me to search in all the sheets of the workbook in row 9 for the value of cell A2 sheet 1 and fetch the data in the target column, provided that there is the word (ok) in column d and copy it in sheet 1 column U starting from cell u10
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Try:
VBA Code:
Sub CopyCell()
    Application.ScreenUpdating = False
    Dim ws As Worksheet, desWS As Worksheet, fnd As Range, Val As String, x As Long: x = 10
    Set desWS = Sheets("Sheet1")
    Val = desWS.Range("A2").Value
    For Each ws In Sheets
        If ws.Name <> "Sheet1" Then
            Set fnd = ws.Rows(9).Find(Val, LookIn:=xlValues, lookat:=xlWhole)
            If Not fnd Is Nothing Then
                If ws.Range("D9") = "ok" Then
                    desWS.Range("U" & x) = fnd
                    x = x + 1
                End If
            End If
        End If
    Next ws
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Solution
Try:
VBA Code:
Sub CopyCell()
    Application.ScreenUpdating = False
    Dim ws As Worksheet, desWS As Worksheet, fnd As Range, Val As String, x As Long: x = 10
    Set desWS = Sheets("Sheet1")
    Val = desWS.Range("A2").Value
    For Each ws In Sheets
        If ws.Name <> "Sheet1" Then
            Set fnd = ws.Rows(9).Find(Val, LookIn:=xlValues, lookat:=xlWhole)
            If Not fnd Is Nothing Then
                If ws.Range("D9") = "ok" Then
                    desWS.Range("U" & x) = fnd
                    x = x + 1
                End If
            End If
        End If
    Next ws
    Application.ScreenUpdating = True
End Sub

Thank you. I hope you can fix the error in this topic so that I can complete what I need, please

 
Upvote 0
The macro already searches for the value in row 9 of each sheet and copies the values into column U starting in row 10 of Sheet1. If that is not happening, could you upload a copy of your file to a free site such as www.box.com or www.dropbox.com. Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here. Explain in detail what you want to do referring to specific cells, rows, columns and sheets using a few examples from your data (de-sensitized if necessary).
 
Upvote 0

Forum statistics

Threads
1,215,168
Messages
6,123,408
Members
449,098
Latest member
ArturS75

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