Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default runtime error 1004



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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default runtime error 1004

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default runtime error 1004

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,119
Default runtime error 1004

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
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
Runtime error 1004 Daniel Excel Programming 2 July 19th 05 04:37 AM
Excel 2003 Macro Error - Runtime error 1004 Cow Excel Discussion (Misc queries) 2 June 7th 05 01:40 PM
Runtime error 1004 Ajit Excel Programming 2 January 13th 05 02:55 PM
Runtime Error '1004' Dean[_4_] Excel Programming 2 January 9th 05 09:02 PM
Runtime error 1004 Jeannette[_2_] Excel Programming 0 May 13th 04 06:31 AM


All times are GMT +1. The time now is 11:15 AM.

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

About Us

"It's about Microsoft Excel"