Home |
Search |
Today's Posts |
#1
|
|||
|
|||
Selection Range
My VBA sometimes works fine with
range("A1").select Bt sometimes, it shows an error unless I include a "activesheet" in front as below : activesheet.range("A1").select Anyone please help me know why the additional "word" is needed ? |
#2
|
|||
|
|||
Could it be that it is a chart sheet that is active, that is a sheet that
doesn't have a range. -- HTH Bob Phillips "ch" wrote in message ... My VBA sometimes works fine with range("A1").select Bt sometimes, it shows an error unless I include a "activesheet" in front as below : activesheet.range("A1").select Anyone please help me know why the additional "word" is needed ? |
#3
|
|||
|
|||
The original text did not turn out correctly. I have removed the inverted
commas in the following lines. My VBA sometimes works fine with range(A1).select Bt sometimes, it shows an error unless I include a activesheet in front as below : activesheet.range(A1).select Anyone please help me know why the additional "word" is needed ? "ch" wrote: My VBA sometimes works fine with range("A1").select Bt sometimes, it shows an error unless I include a "activesheet" in front as below : activesheet.range("A1").select Anyone please help me know why the additional "word" is needed ? |
#4
|
|||
|
|||
I don't think so. I do not work on chart sheets at all in VBA and normal
Excel. "Bob Phillips" wrote: Could it be that it is a chart sheet that is active, that is a sheet that doesn't have a range. -- HTH Bob Phillips "ch" wrote in message ... My VBA sometimes works fine with range("A1").select Bt sometimes, it shows an error unless I include a "activesheet" in front as below : activesheet.range("A1").select Anyone please help me know why the additional "word" is needed ? |
#5
|
|||
|
|||
My bet is that
range("a1").select works fine in a General module, but you're having trouble when the code is in a worksheet module. When you type: range("a1").select Then this unqualified range will refer to the activesheet in a General module, but it'll refer to the sheet that owns the code when it's in the worksheet module. And I'm betting you do something like this (behind sheet1): worksheets("Sheet2").select range("a1").select Since that second line is still refering to sheet1 and since you can't select a range on a sheet that is not active, then you get the error. You could do: with worksheets("sheet2") .select .range("a1").select end with But if you're changing a value (say), you could just work on it directly: worksheets("sheet2").range("a1").value = "hi There!" Then you don't need to select the sheet or the range. ch wrote: My VBA sometimes works fine with range("A1").select Bt sometimes, it shows an error unless I include a "activesheet" in front as below : activesheet.range("A1").select Anyone please help me know why the additional "word" is needed ? -- Dave Peterson |
#6
|
|||
|
|||
Thanks Dave! You found the source of my problem!
"Dave Peterson" wrote: My bet is that range("a1").select works fine in a General module, but you're having trouble when the code is in a worksheet module. When you type: range("a1").select Then this unqualified range will refer to the activesheet in a General module, but it'll refer to the sheet that owns the code when it's in the worksheet module. And I'm betting you do something like this (behind sheet1): worksheets("Sheet2").select range("a1").select Since that second line is still refering to sheet1 and since you can't select a range on a sheet that is not active, then you get the error. You could do: with worksheets("sheet2") .select .range("a1").select end with But if you're changing a value (say), you could just work on it directly: worksheets("sheet2").range("a1").value = "hi There!" Then you don't need to select the sheet or the range. ch wrote: My VBA sometimes works fine with range("A1").select Bt sometimes, it shows an error unless I include a "activesheet" in front as below : activesheet.range("A1").select Anyone please help me know why the additional "word" is needed ? -- Dave Peterson |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Cannot Expand Named Range - when size of the Range exceeds | Excel Discussion (Misc queries) | |||
can a formula check for a certain value in a range? | Excel Discussion (Misc queries) | |||
Define a range based on another named range | Excel Worksheet Functions | |||
random selection from a range of cells | Excel Worksheet Functions | |||
named range refers to: in a chart | Excel Discussion (Misc queries) |