VB code Find a variable value

owendodd

Board Regular
Joined
Jan 17, 2005
Messages
205
Hi,

Below is the macro code for entering a code into a cell (H3) and finding this code value in another sheet. I can only do this as a constant. Would anyone know how i could take the value in as a variable meaning and find the value based on the number entered

ActiveCell.FormulaR1C1 = ""
Sheets("Sep").Select
Range("H3").Select
Selection.Copy
Sheets("SCHEDULE2").Select
Columns("A:A").Select
Selection.Find(What:="", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
Rows("344:344").Select
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Do you mean?

Selection.Find(What:=Sheets("Sep").Range("H3").Value, After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
 
Upvote 0
something like this? It assumes there is already a code in H3 and then activates the cell where it founds the code. Gives a message if the code is not found:
Code:
Sub TestFind()

    Dim rngTarget As Range
    Dim rngFound As Range
    Dim SearchFor

    Set rngTarget = Sheets("SCHEDULE2").Cells
    SearchFor = Sheets("Sep").Range("H3")

    Set rngFound = rngTarget.Find(SearchFor)
    
    If Not rngFound Is Nothing Then
        rngFound.Activate
    Else
         msgbox "Code not Found"
    End If
End Sub
 
Upvote 0
Yes, something like that, How would i apply this to my code above. I am not a VB programmer so have had problems with this.

Thanks for your assistance!
 
Upvote 0
Jus another question i would like to do the same with for when i go browse down on column C i select a cell that contains a code. When i run the macro it finds this code on column C on the other worksheet that i have.

Any ideas
 
Upvote 0
it's exactly the same, but change the following:

1) sheet names to whatever they are

2) replace the SearchFor= line with:
Code:
SearchFor = Activecell.value
 
Upvote 0

Forum statistics

Threads
1,217,756
Messages
6,138,428
Members
450,136
Latest member
Tabako1960

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