How to get the found data onanother column with find all on vba?

studentlearner

New Member
Joined
Oct 7, 2021
Messages
30
Office Version
  1. 365
Platform
  1. Windows
so currently I can find the whole column according to a specific cell value, but now I require it to find another column based on the found values. any help would be great thanks!


Sub findAll()
Dim c As Range
Dim findWhat As String
Dim i As Long

i = 2




With Worksheets(1).Range("C:C")


Set c = .Find(What:=Range("P2").Value, LookIn:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address

Do
Cells(i, 17) = c.Value
Set c = .FindNext(c)
i = i + 1
Loop While Not c Is Nothing And c.Address <> firstAddress
End If

End With

End Sub

So right now I wish to get the found data of column 'G' together with the found data.
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Hi,

You can use Range.offset property to return a value from another column

example

Rich (BB code):
Option Explicit
Sub findAll()
    Dim c           As Range
    Dim findWhat    As String, firstAddress As String
    Dim i           As Long
  
    i = 2
  
    With Worksheets(1)
  
    findWhat = .Range("P2").Value
      
        Set c = .Range("C:C").Find(What:=findWhat, LookIn:=xlValues)
      
        If Not c Is Nothing Then
            firstAddress = c.Address
          
            Do
                .Cells(i, 17) = c.Value
              
                .Cells(i, 18) = c.Offset(, 4).Value
              
                Set c = .Range("C:C").FindNext(c)
                If c Is Nothing Then Exit Do
                i = i + 1
            Loop While c.Address <> firstAddress
          
        End If
      
    End With
  
End Sub



Hope helpful



Dave
 
Last edited:
Upvote 0
Solution

Forum statistics

Threads
1,214,996
Messages
6,122,636
Members
449,092
Latest member
bsb1122

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