Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
Ayo Ayo is offline
external usenet poster
 
Posts: 489
Default "Select method of Range class failed" Error

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
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default "Select method of Range class failed" Error

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.

Ayo wrote:

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


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,942
Default "Select method of Range class failed" Error

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

"Ayo" wrote:

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

  #4   Report Post  
Posted to microsoft.public.excel.misc
Ayo Ayo is offline
external usenet poster
 
Posts: 489
Default "Select method of Range class failed" Error

Thank you Dave. That worked.

"Dave Peterson" wrote:

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.

Ayo wrote:

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


--

Dave Peterson

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Autofill method of range class failed Don Guillett Excel Discussion (Misc queries) 0 February 27th 08 03:56 PM
Autofill method of range class failed Appache Excel Discussion (Misc queries) 5 February 27th 08 03:37 PM
Runtime 1004 error -- insert method of range class failed. tish Excel Discussion (Misc queries) 1 June 1st 07 04:04 PM
Run-Time error '1004' : Select method of Range class failed [email protected] Excel Discussion (Misc queries) 3 March 9th 07 01:36 PM
Run-time error "1004" Select method of range class failed Tallan Excel Discussion (Misc queries) 3 March 7th 07 05:22 PM


All times are GMT +1. The time now is 01:33 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"