Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() Dim ws2 As Worksheet Dim ws2R As Integer Set ws2 = Worksheets("PDFs") ws2R = 20 ws2.Range(Cells(1, 1), Cells(ws2R, 9)).Select In the code above I always get runtime error 1004 on the last line. PDFs is a valid sheet name. Can someone please tell me why this does not work? Thank you - jc - |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi JC
The code is OK if PDFs is a active sheet. if is not try Dim ws2 As Worksheet Dim ws2R As Integer Set ws2 = Worksheets("PDFs") ws2R = 20 ws2.select ws2.Range(Cells(1, 1), Cells(ws2R, 9)).Select "JC" wrote in message oups.com... Dim ws2 As Worksheet Dim ws2R As Integer Set ws2 = Worksheets("PDFs") ws2R = 20 ws2.Range(Cells(1, 1), Cells(ws2R, 9)).Select In the code above I always get runtime error 1004 on the last line. PDFs is a valid sheet name. Can someone please tell me why this does not work? Thank you - jc - |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Carlos & Jim,
You were both right! Thank you! - that allowed me to select the required cells; however, maybe you can clear something up for me. In the code of my macro the previous line reads: ws2.Cells.Clear and I execute that command while WS1 sheet is active. Is this "need to be on the active sheet" dependent on which command you are trying to execute (it appears to be) and if so is there any publication that will tell me which command requires the sheet to be active? Normally when I write macros involving more than one sheet I try to limit the number of times that the screen flashes between the different sheets and that is what I was trying to prevent in my original lines of code. Thank you again for such a quick and accurate response - - jc - |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Cells will return to the active sheet unless you specify otherwise. You also
need to select the shet if it is not active. Give this a try... Dim ws2 As Worksheet Dim ws2R As Integer Set ws2 = Worksheets("PDFs") ws2R = 20 with ws2 ..select ..Range(.Cells(1, 1), .Cells(ws2R, 9)).Select end with -- HTH... Jim Thomlinson "JC" wrote: Dim ws2 As Worksheet Dim ws2R As Integer Set ws2 = Worksheets("PDFs") ws2R = 20 ws2.Range(Cells(1, 1), Cells(ws2R, 9)).Select In the code above I always get runtime error 1004 on the last line. PDFs is a valid sheet name. Can someone please tell me why this does not work? Thank you - jc - |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Runtime error 1004 | Excel Programming | |||
Excel 2003 Macro Error - Runtime error 1004 | Excel Discussion (Misc queries) | |||
Runtime error 1004 | Excel Programming | |||
Runtime Error '1004' | Excel Programming | |||
Runtime error 1004 | Excel Programming |