I'm stuck (again)

  • Thread starter Thread starter Himszy
  • Start date Start date
H

Himszy

Hi

I'm trying to write that if a variable equals a value then find a cell that
equals the same amount and type in another variables value in to the cell
next to it.

Thanks Michael
 
Dim rng as Range
Dim myVar as Long
myVar = 10
set rng = cells.find(10)
if not rng is nothing then
rng.offset(0,1).Value = 20
end if
 
Michael

I think I understand, try and work this through

Sub TwoVariables()
Dim Var1 As Variant, Var2 As Variant
Dim RFound As Range
Var1 = "Nick"
Var2 = "NotNick"
Set RFound = Worksheets("Sheet1").Range("A1:A100").Find _
(Var1, LookIn:=xlValues)
If Not RFound Is Nothing Then
RFound.Offset(0, 1).Value = Var2
End If
End Sub

--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
(e-mail address removed)
 
Not to be picky since this is excelent code, but I think that it should read...

set rng = cells.find(myVar)

Tom you really write the nicest code...
 
Jim,

good catch, thanks.

--
Regards,
Tom Ogivy

Jim Thomlinson said:
Not to be picky since this is excelent code, but I think that it should read...

set rng = cells.find(myVar)

Tom you really write the nicest code...
 
Nick Hodge said:
Michael

I think I understand, try and work this through

Sub TwoVariables()
Dim Var1 As Variant, Var2 As Variant
Dim RFound As Range
Var1 = "Nick"
Var2 = "NotNick"
Set RFound = Worksheets("Sheet1").Range("A1:A100").Find _
(Var1, LookIn:=xlValues)
If Not RFound Is Nothing Then
RFound.Offset(0, 1).Value = Var2
End If
End Sub

--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
(e-mail address removed)

Thanks Tom, Jim and Nick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top