ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Referencing variable (https://www.excelbanter.com/excel-programming/284436-referencing-variable.html)

Lee

Referencing variable
 
I want to run the followingcode in specific columns, but
in several different rows. The columns will always stay
the same, but the number of rows will be different each
time I run the code.

If Range("h2") = "Procedural" Then
Range("j2").Formula = "Procedural"
Exit Sub
ElseIf Range("f2") 0 Then
Range("j2").Formula = "Overpayment"
ElseIf Range("g2") 0 Then
Range("j2").Formula = "Underpayment"
End If

I'm using a count procedure to count number of rows in the
usedrange, and figured I'd use a loop statement, but I
can't see how to reference the rows as variables.

Thanks,
Lee

Tom Ogilvy

Referencing variable
 
for i = 2 to 100
If Cells(i,8) = "Procedural" then
Cells(i,10).Formula = "Procedural"
exit Sub
Elseif

and so forth.

Replace 100 with a variable that contains your count.

--
Regards,
Tom Ogilvy


"Lee" wrote in message
...
I want to run the followingcode in specific columns, but
in several different rows. The columns will always stay
the same, but the number of rows will be different each
time I run the code.

If Range("h2") = "Procedural" Then
Range("j2").Formula = "Procedural"
Exit Sub
ElseIf Range("f2") 0 Then
Range("j2").Formula = "Overpayment"
ElseIf Range("g2") 0 Then
Range("j2").Formula = "Underpayment"
End If

I'm using a count procedure to count number of rows in the
usedrange, and figured I'd use a loop statement, but I
can't see how to reference the rows as variables.

Thanks,
Lee





All times are GMT +1. The time now is 12:34 PM.

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