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

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
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,220,965
Messages
6,157,119
Members
451,399
Latest member
alchavar

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