View Full Version : Solved: Selecting a Cell on a worksheet.
Okay I'm cleaning up my program to make it run as fast as I can, so I'm using direct references instead of activating bunches of different sheets. Here's the code that I have:
Worksheets("BAT Files").Range("B" & (xbat + 2)).Select
Worksheets("BAT Files").Hyperlinks.Add Anchor:=Selection, Address:=myFS.Getfolder(path) & "\" & myFile.Name, TextToDisplay:="Open File"
With Selection.Font
.Name = "Arial"
.Size = 8
End With
Apparently I can't do a Worksheets().Range().Select. I can do a Range().Select if the worksheet is activated. Is there a way to do this?
RichardSchollar
07-13-2007, 09:11 AM
You can only select a cell on the Activesheet. You don't (usually) need to select anything to work with a range howver. Why don't you just set a range reference to the cell(s) you want to work with and then make use of that? eg
Set rng = Worksheets("BAT Files").Range("B" & (xbat + 2))
Worksheets("BAT Files").Hyperlinks.Add Anchor:=rng, Address:=myFS.Getfolder(path) & "\" & myFile.Name, TextToDisplay:="Open File"
With rng.Font
.Name = "Arial"
.Size = 8
End With
Richard
Yeah that will work. I was hoping there was something I hadn't come across which would let me select a cell. I can understand why you couldn't if the sheet isn't active though. I just didn't want to be activating one of 9 different sheets for each file found. Even with screen updating off I would think that would be slower somewhat.
Thanks for the suggestion :)
Norie
07-13-2007, 10:29 AM
OdiN
As Richard has pointed out you don't need to select, and you also don't need to activate either.
OdiN
As Richard has pointed out you don't need to select, and you also don't need to activate either.
If you want to select, you do have to activate ;)
I just didn't want to do that.
If you could select a cell on a worksheet that isn't active then it would cut down on the number of lines in the code.
Norie
07-13-2007, 11:31 AM
But you do not need to select in the first place.:)
Bob Phillips
07-13-2007, 11:51 AM
What everyone is saying is that you refrence a cell on a worksheet. Don't select it, but process by reference, and there is no need to activate. A paradigm shift.
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.