"Select method of Range class failed" Error

A

Ayo

I am getting this error message in my code but the code ha being working
perfectly well before with no issues or errors. The error occurs on this line:
"Sheets("Site Lists").Range("V" & rwNum).Select"
I tried "Worksheets("Site Lists").Range("V" & rwNum).Select" and got the
same error. Any ideas?

For Each c In Worksheets("Sites Table").Range("B2:B" & totalSiteCount).Cells
If c.Value <> "" And IsDate(c.Offset(0, 9).Value) Then
Worksheets("Site Lists").Range("U" & rwNum).Value = siteNum
Worksheets("Site Lists").Range("V" & rwNum).Value = c.Value
Worksheets("Site Lists").Range("W" & rwNum).Value =
Mid(c.Offset(0, 2).Value, 5)
Sheets("Site Lists").Range("V" & rwNum).Select
Selection.Interior.ColorIndex = 6
rwNum = rwNum + 1
siteNum = siteNum + 1
End If
Next c
 
D

Dave Peterson

You have to select a sheet before you select a range on that sheet.

Sheets("Site Lists").select
Sheets("Site Lists").Range("V" & rwNum).Select
Selection.Interior.ColorIndex = 6

But even better is to not select anything at all:
Sheets("Site Lists").Range("V" & rwNum).Interior.ColorIndex = 6

It makes the code easier to read and update and makes the code run a bit faster.
 
F

FSt1

hi
you can only select on the active sheet. are you sure you are on sheet "site
lists" and that the sheet name exists?

regards
FSt1
 
A

Ayo

Thank you Dave. That worked.

Dave Peterson said:
You have to select a sheet before you select a range on that sheet.

Sheets("Site Lists").select
Sheets("Site Lists").Range("V" & rwNum).Select
Selection.Interior.ColorIndex = 6

But even better is to not select anything at all:
Sheets("Site Lists").Range("V" & rwNum).Interior.ColorIndex = 6

It makes the code easier to read and update and makes the code run a bit faster.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top