Row number as a variable in cell references

ChristineJ

Well-known Member
Joined
May 18, 2009
Messages
761
Office Version
  1. 365
Platform
  1. Windows
This is a short excerpt of code that relates to row 16. I need to repeat the same thing for other rows. The column letters will not change.
Is it possible to make the "16" throughout the code a variable so I can call the Review macro and enter in the row number?

Code:
Sub Review()
Range("P16").ClearComments
Call Condo("P16", "CC16")

Range("P16").Offset(0, 3).Formula = "=FORMULATEXT(CF16)"

If Range("P16").Value = Range("CF16").Value Then
    Range("P16").Offset(0, 1).Value = "  " & ChrW(&H2713)  
   
    If IsNumeric(Range("P16").Formula) = True Then
    Range("CG16").Value = "X"
    Range("CE16").Value = 2
    Else
    
    If IsNumeric(Right(Range("P16").Formula, Len(Range("P16").Formula) - 1)) Then
    
    Range("CG16").Value = "X" & vbCrLf & Range("CC16").Value
   Range("CE16").Value = 2
     Else
     
     If InStr(Range("P16").Formula, "$") > 0 Then
Range("CI16").Value = "NO"
End If
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Use the Cells property rather than the Range property

use Cells(rowNumber, 16) instead of Range("P16") throughout (note P is the 16th column, the second argument is the column reference, not a the row reference)
 
Upvote 0
Use the Cells property rather than the Range property

use Cells(rowNumber, 16) instead of Range("P16") throughout (note P is the 16th column, the second argument is the column reference, not a the row reference)
OK, I can do that and refer to all the column letters in the code by their numbers in the second argument.

How do I make "rowNumber" a variable when I call the Review macro?

In this case I want the row number to be 16 as well. But I also want to run the same code for other rows.

Thanks!
 
Upvote 0

Forum statistics

Threads
1,214,585
Messages
6,120,391
Members
448,957
Latest member
Hat4Life

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