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

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
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
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,213,529
Messages
6,114,155
Members
448,554
Latest member
Gleisner2

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