Selecting a range using cells(x,x)

lhernandez

Active Member
Joined
May 22, 2006
Messages
282
Hello,
I am trying to select a range for an unknown variable. I have a macro searching for a match, once found it is printed in a different worksheet, if the variable is not found I would like to highlight it in the original sheet and on the new worksheet.
So, for example, I am using j to increment through the rows of the original sheet to find a match and
if vrFound = false then
I would like to select the row and highlight it in sheet one (original sheet)
and select the row and highlight it in sheet2 (new sheet.)
I am using
Code:
If vrFound = False Then
                    Worksheets("Sheet1").Cells(j, 1).Select to Worksheets("Sheet1").Cells(j, 16).Select 
            With Selection.Interior
                .ColorIndex = 6
                .Pattern = xlSolid
            End With
end if
of course this does not work and I have tried
Code:
 If vrFound = False Then
                    Worksheets("Sheet1").range("Aj:Ap").Select             
With Selection.Interior
                .ColorIndex = 6
                .Pattern = xlSolid
            End With
end if
and this does not work either.
Anything would help
Thank you
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
Try:

Code:
If vrFound = False Then
   With Worksheets("Sheet1")
      With .Range(.Cells(j, 1),.Cells(j, 16)).Interior 
        .ColorIndex = 6 
        .Pattern = xlSolid 
      End With 
   End With
End If
 

Von Pookie

MrExcel MVP
Joined
Feb 17, 2002
Messages
13,686
Are you wanting something like this?

Code:
If vrFound = False Then
     With Sheets("Sheet1")
          Range(.Cells(j, 1), .Cells(j, 16)).Interior.ColorIndex = 6
     End With
End If
 

Forum statistics

Threads
1,136,712
Messages
5,677,330
Members
419,688
Latest member
sarahmichelle

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
Top