Which variable to use

BobbyJack

New Member
Joined
Jul 22, 2009
Messages
18
Hi

I am declaring this as a string but I get a debug type miss match error.

Dim ProposalYear As String

ProposalYear = Worksheets("Calculation Matrix").Range("L41:M41").Value

L41:M41 is a merged cell is this the best way to declare this.

Thanks
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
VBA hates merged cells. Much better use Center Across Selection and then just:

Code:
Dim ProposalYear As String
ProposalYear = Worksheets("Calculation Matrix").Range("L41").Value

Dom
 
Upvote 0
I hate merged cells and avoid them like the plague! However...

What is returned if you use:

Code:
Dim ProposalYear as String
 
ProposalYear = Sheets("Calculation Matrix").Range("[B][COLOR=red]L41[/COLOR][/B]").Text
 
Upvote 0
Merged cells are the devil's work.

Suspect you'll have to just refer to L41.

Not sure whether the String data type is particularly bomb-proof when referring to the value of a cell (and will certainly fail if the cell contains an error value).
 
Upvote 0
Not sure whether the String data type is particularly bomb-proof when referring to the value of a cell (and will certainly fail if the cell contains an error value).

Hence use .Text property instead of .Value...
 
Upvote 0
Oh yeah, of course!

.Text returns the displayed value rather than the held value, right?
 
Upvote 0
Kinda, but rather than saying 'displayed value' I'd just say that it returns the String value of the range (when referring to the range that is)...
 
Upvote 0
Thanks everyone

I have only taken the first part of the cell "L41" and it is now working

thanks again
 
Upvote 0

Forum statistics

Threads
1,214,522
Messages
6,120,022
Members
448,939
Latest member
Leon Leenders

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top