|
-
Mar 21st, 2006, 01:29 PM
#1
Thread Starter
Addicted Member
Using the cell property inside the range
Hi everyone.
I will start with the code:
VB Code:
ItemCellDbl = CDbl(Worksheets("MEDIA").Range(ItemCell).Text)
ItemCell is a string, and this code works fine if ItemCell Equals something like "E5".
If ItemCell Equals "Cells(6, 30), Cells(6, 30)" I get an error:
Run-time error '1004':
Application-defined or object-defined error.
What is strange though is that the following code works just fine:
VB Code:
Debug.Print CDbl(Worksheets("MEDIA").Range(Cells(6, 30), Cells(6, 30)).Text)
Does maybe ItemCell being a string have anything to do with this error ?
-
Mar 21st, 2006, 01:39 PM
#2
Re: Using the cell property inside the range
Of course. You can't pass a string variable and expect that to be interpreted into an actual reference.
In the case of a LetterNumber reference, Excel recognises it because the name of the cell, E5, is defined in the Name box in the top corner. You can rename any cell or range to anything you like, or leave them in the A1 default style, but you're still referencing a cell or range by name. It is not interpreting your string and converting that into a cell reference. Hence you can't put in "Cell(6,1)" and expect it to find cell F1, it's looking for a cell or range named "Cell(6,1)".
In your second example, you're not passing it a string, you're actually giving it cells to look at, so there is no problem.
zaza
-
Mar 21st, 2006, 02:18 PM
#3
Thread Starter
Addicted Member
Re: Using the cell property inside the range
Thanks for the reply,
Could I have ItemCell as something else beside string and still have the code work?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|