Formula in a variable

288enzo

Well-known Member
Joined
Feb 8, 2009
Messages
721
Office Version
  1. 2016
Platform
  1. Windows
I've found much on how to use a variable in a formula, but how if possible do I use a formula for my variable?

As an example, in B5 I have 83a West Coast. I want my string variable to be =LEFT(B5,2)

The reason is because I plan on using Select Case.

VBA Code:
Dim strArea As String
strArea = Sheets("Dealer Status").Range("Left(B5,2)")
Range("B:B").Delete
Select Case strArea
Case 83
Range("C2") = "00"
End Select

Another reason why I want to assign it to a String is because I plan on deleting the B column and will need to use the String after deleting the column.

I also tried
VBA Code:
Dim strArea As String
strArea = Sheets("Dealer Status").Range("B5") = "=Left(B5,2)"
Range("B:B").Delete
Select Case strArea
Case 83
Range("C2") = "00"
End Select
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
How about
VBA Code:
Sub test()
Dim strArea As String
strArea = Left(Sheets("Dealer Status").Range("B5"), 2)
Range("B:B").Delete
Select Case strArea
Case 83
Range("C2") = "00"
End Select
End Sub
 
Upvote 0
Solution
How about
VBA Code:
Sub test()
Dim strArea As String
strArea = Left(Sheets("Dealer Status").Range("B5"), 2)
Range("B:B").Delete
Select Case strArea
Case 83
Range("C2") = "00"
End Select
End Sub
Thank you very much. What you did makes sense.
 
Upvote 0

Forum statistics

Threads
1,215,028
Messages
6,122,753
Members
449,094
Latest member
dsharae57

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