VBA Find Function

2000km12

New Member
Joined
Apr 19, 2023
Messages
15
Office Version
  1. 365
Platform
  1. Windows
Hello! I am attempting to use the VBA "Find" function to locate a certain value in a worksheet. Once I find this value, I want to copy a value from a different column, in that same row. I'm unsure how to do this. Does anyone have recommendations?

I am relatively new to coding in general.

Thanks
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
I am attempting to use the VBA "Find" function to locate a certain value in a worksheet. Once I find this value, I want to copy a value from a different column, in that same row.
Find in what column? copy from what column? then paste it where?
 
Upvote 0
Use the range offset property together with the range copy method. Example:

VBA Code:
Sub Test()
    Dim FoundRange As Range
    Dim SearchTerm As String
    
    'Look for something
    SearchTerm = "Nugget"
    Set FoundRange = ActiveSheet.UsedRange.Find(What:=SearchTerm)
    
    'If found
    If Not FoundRange Is Nothing Then
        
        'Copy some other cell in the same row but a different column, relative to the first cell
        FoundRange.Offset(0, 4).Copy
        
        'Paste it somewhere
        ActiveSheet.Range("A1").PasteSpecial (xlPasteValues)
    Else
        MsgBox "'" & SearchTerm & "' not found"
    End If
End Sub
 
Upvote 1
Solution
Use the range offset property together with the range copy method. Example:

VBA Code:
Sub Test()
    Dim FoundRange As Range
    Dim SearchTerm As String
   
    'Look for something
    SearchTerm = "Nugget"
    Set FoundRange = ActiveSheet.UsedRange.Find(What:=SearchTerm)
   
    'If found
    If Not FoundRange Is Nothing Then
       
        'Copy some other cell in the same row but a different column, relative to the first cell
        FoundRange.Offset(0, 4).Copy
       
        'Paste it somewhere
        ActiveSheet.Range("A1").PasteSpecial (xlPasteValues)
    Else
        MsgBox "'" & SearchTerm & "' not found"
    End If
End Sub
Thank you! I will try this out!
 
Upvote 0
Find in what column? copy from what column? then paste it where?
A value will need to be found in column A, then the value to be copied will be from that same row, but from column G. It will then be pasted on another worksheet; which i do know how to do already.

Thanks
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

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