Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Kassie
 
Posts: n/a
Default I cannot select a range

I wrote a macro, inter alia containing the following code:

Const constName = "JCMail.xls"
Const constPre = "JC"

Private Sub CommandButton1_Click()
' Application.ScreenUpdating = False
' Gets and Inserts job card number
Range("AB3").Select
' CommandButton1.Deactivate
varRef = ActiveCell.Value
copier
End Sub

Private Sub copier()
' Copies and pastes date
Windows(constName).Activate
Range("G3").Select

When the macro reaches the last line of code (Range("G3").Select), I get the
following error message:

Run-time Error 1004:
Select method of Range class failed

I have used the exact phrase in so many other macros, and it has always
worked. Why can't I do it here? I use this macro to copy info from one
sheet to another (in this case from an input sheet into a jobcard).


  #2   Report Post  
Earl Kiosterud
 
Posts: n/a
Default

Kassie,

Use a break (F9 on that line), and Alt-Tab back to Excel. Ensure that the
desired worksheet is active, not perhaps a chart sheet or something. See if
whatever the active sheet is has anything that would disallow selecting your
range.

--
Earl Kiosterud
mvpearl omitthisword at verizon period net
-------------------------------------------

"Kassie" wrote in message
...
I wrote a macro, inter alia containing the following code:

Const constName = "JCMail.xls"
Const constPre = "JC"

Private Sub CommandButton1_Click()
' Application.ScreenUpdating = False
' Gets and Inserts job card number
Range("AB3").Select
' CommandButton1.Deactivate
varRef = ActiveCell.Value
copier
End Sub

Private Sub copier()
' Copies and pastes date
Windows(constName).Activate
Range("G3").Select

When the macro reaches the last line of code (Range("G3").Select), I get
the
following error message:

Run-time Error 1004:
Select method of Range class failed

I have used the exact phrase in so many other macros, and it has always
worked. Why can't I do it here? I use this macro to copy info from one
sheet to another (in this case from an input sheet into a jobcard).




  #3   Report Post  
Dave Peterson
 
Posts: n/a
Default

And you usually don't have to select/activate something to work with it:

Private Sub copier()
' Copies and pastes date
with workbooks(constName).worksheets("sheet1") '???
.range("g3").copy _
destination:=.range("g6")
end with
end sub

(I have no idea what's really be copied or where you're pasting it though--or
what the worksheet name really is.)

Kassie wrote:

I wrote a macro, inter alia containing the following code:

Const constName = "JCMail.xls"
Const constPre = "JC"

Private Sub CommandButton1_Click()
' Application.ScreenUpdating = False
' Gets and Inserts job card number
Range("AB3").Select
' CommandButton1.Deactivate
varRef = ActiveCell.Value
copier
End Sub

Private Sub copier()
' Copies and pastes date
Windows(constName).Activate
Range("G3").Select

When the macro reaches the last line of code (Range("G3").Select), I get the
following error message:

Run-time Error 1004:
Select method of Range class failed

I have used the exact phrase in so many other macros, and it has always
worked. Why can't I do it here? I use this macro to copy info from one
sheet to another (in this case from an input sheet into a jobcard).


--

Dave Peterson
  #4   Report Post  
Kassie
 
Posts: n/a
Default

Thanks for the comments. Clearly, I did not describe the problem correctly
or well enough. I think the key phrase in my question was: "This macro is
used to copy information from one sheet to another". When I changed the
Private Sub to Sub only, the macro started working correctly. I really
appreciate your input though.

Kind regards

Kassie

"Kassie" wrote:

I wrote a macro, inter alia containing the following code:

Const constName = "JCMail.xls"
Const constPre = "JC"

Private Sub CommandButton1_Click()
' Application.ScreenUpdating = False
' Gets and Inserts job card number
Range("AB3").Select
' CommandButton1.Deactivate
varRef = ActiveCell.Value
copier
End Sub

Private Sub copier()
' Copies and pastes date
Windows(constName).Activate
Range("G3").Select

When the macro reaches the last line of code (Range("G3").Select), I get the
following error message:

Run-time Error 1004:
Select method of Range class failed

I have used the exact phrase in so many other macros, and it has always
worked. Why can't I do it here? I use this macro to copy info from one
sheet to another (in this case from an input sheet into a jobcard).


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
Select a range Kevin Excel Discussion (Misc queries) 3 February 18th 05 11:04 PM
Dynamic Formulas with Dynamic Ranges Ralph Howarth Excel Worksheet Functions 5 January 21st 05 08:44 AM
How do I select a range if one cells contents is equal to another KHarrison Excel Discussion (Misc queries) 2 December 20th 04 09:35 PM
named range refers to: in a chart Spencer Hutton Excel Discussion (Misc queries) 1 December 14th 04 10:15 PM
Formula to list unique values JaneC Excel Worksheet Functions 4 December 10th 04 12:25 AM


All times are GMT +1. The time now is 01:50 PM.

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"