sheet name with cell string in vba

BiKeTa

New Member
Joined
Mar 31, 2018
Messages
15
i want to know how to use a string in VBA to find a worksheet based on the contents of a cell
i thought this would work but cant seemed to figure out what keeps throwng an error

Code:
Private Sub CommandButton1_Click()

Dim shtName As String
Dim rngAddress As String
shtName = Range("b5").Value
rngAddress = Range("c5").Value
Sheets(shtName).Range(rngAddress).Value = Range(b8).Value




End Sub
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
You are missing the double-quotes around the B8, i.e.
Code:
[COLOR=#333333]Sheets(shtName).Range(rngAddress).Value = Range([/COLOR][COLOR=#ff0000][B]"[/B][/COLOR][COLOR=#333333]B8[/COLOR][COLOR=#ff0000][B]"[/B][/COLOR][COLOR=#333333]).Value[/COLOR]
 
Upvote 0
sweet lord. thank you i had banged my head against the keyboard all morning over this. works like a dream.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

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