ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Its so simple! Why won't it work! (https://www.excelbanter.com/excel-programming/345199-its-so-simple-why-wont-work.html)

Kevin O'Neill[_2_]

Its so simple! Why won't it work!
 
I'm going mad. I've tried so many different ways. I've even had it
work, save the project, come back 30 min. later, and then doesn't work.

No changes made.


All I'm trying to do is Select a cell from another sheet.


I'd prefer to select the sheet using: Sheet12 ; rather than it's name:
Loads & I have to use Cells()


Tried these and more...
Worksheets("Loads").Cells(8, 41).Select
Sheet12.Cells(8, 41).Select


"Select Method of Range Class Failed" - error
I assume that has something to do with the '.select'


Chip Pearson

Its so simple! Why won't it work!
 
You can't select cells on a sheet that is not the active sheet.
You have to select the sheet first, then the cells. E.g.,

Worksheets("Loads").Select
Cells(8,14).Select

Of course, it is rarely necessary to use Select in the first
place, so if you post what you are ultimately trying to do,
someone may have an idea how to accomplish it without having to
select a range.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com




"Kevin O'Neill" wrote in message
ups.com...
I'm going mad. I've tried so many different ways. I've even had
it
work, save the project, come back 30 min. later, and then
doesn't work.

No changes made.


All I'm trying to do is Select a cell from another sheet.


I'd prefer to select the sheet using: Sheet12 ; rather than
it's name:
Loads & I have to use Cells()


Tried these and more...
Worksheets("Loads").Cells(8, 41).Select
Sheet12.Cells(8, 41).Select


"Select Method of Range Class Failed" - error
I assume that has something to do with the '.select'




Kevin O'Neill[_2_]

Its so simple! Why won't it work!
 
Chip thanks. Worked like a charm. I'm not a programmer by trade, my
Boss always tells me there's no need to 'select' things, but I always
do it anyway. I don't know any better.


Chip Pearson

Its so simple! Why won't it work!
 
I'm glad it works. You rarely need to Select a range, and doing
so is a very slow operation. Instead of Selecting, you can use a
Range variable Set to the appropriate range, and use that
variable. For example, instead of


Range("A1").Select
Selection.Font.Bold = True

you could use

Range("A1").Font.Bold = True
or
Dim Rng As Range
Set Rng = Range("A1")
Rng.Font.Bold = True

Because Selection can be any type of object in addition to a
range (a Shape, a Chart, etc), a lot of code must execute behind
the scenes to determine what type of object Selection actually
is.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"Kevin O'Neill" wrote in message
oups.com...
Chip thanks. Worked like a charm. I'm not a programmer by
trade, my
Boss always tells me there's no need to 'select' things, but I
always
do it anyway. I don't know any better.




Kevin O'Neill[_2_]

Its so simple! Why won't it work!
 
Thanks Chip, I'll work that method into my next project. That makes
sense though.



All times are GMT +1. The time now is 01:14 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com