ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   I'm stuck (again) (https://www.excelbanter.com/excel-programming/319894-im-stuck-again.html)

Himszy

I'm stuck (again)
 
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



Tom Ogilvy

I'm stuck (again)
 
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

--
Regards,
Tom Ogilvy

"Himszy" wrote in message
. ..
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





Nick Hodge

I'm stuck (again)
 
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
HIS


"Himszy" wrote in message
. ..
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





Jim Thomlinson[_3_]

I'm stuck (again)
 
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...

"Tom Ogilvy" wrote:

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

--
Regards,
Tom Ogilvy

"Himszy" wrote in message
. ..
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






Tom Ogilvy

I'm stuck (again)
 
Jim,

good catch, thanks.

--
Regards,
Tom Ogivy

"Jim Thomlinson" wrote in message
...
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...

"Tom Ogilvy" wrote:

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

--
Regards,
Tom Ogilvy

"Himszy" wrote in message
. ..
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








Himszy

I'm stuck (again)
 

"Nick Hodge" wrote in message
...
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
HIS


"Himszy" wrote in message
. ..
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





Thanks Tom, Jim and Nick




All times are GMT +1. The time now is 01:56 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com