using a string value in the VB code itself

stonypaul

Board Regular
Joined
Jan 4, 2008
Messages
86
Is it possible to declare a string variable which is the contents of a referenced cell and then use that string in the VB code itself?

For instance if a String variable is declared like this:

Dim stringTest As String = 'the contents of sheet01, cell A1'

Not sure how the code would go on the r/h side of the equals?

So if cell A1 in sheet01 contained the string 'wk52' would the first line of code below be understood as Sheets("wk52").Select ?


Sheets(stringTest).Select
ActiveSheet.Unprotect
Range("AA52:AD53").Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorDark1
.TintAndShade = -0.249977111117893
.PatternTintAndShade = 0


Therefore you have the option of making changes to sheets using a macro and selecting the sheet to be changed by just typing it into a cell.
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Try like this

Code:
Dim stringTest As String
stringTest = Sheets("sheet01").Range("A1").Value
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,836
Members
452,947
Latest member
Gerry_F

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