Macro sheet find

fari1

Active Member
Joined
May 29, 2011
Messages
362
Hi,
I'm having problem with following vba code

Sub Macro1()
'
' Macro1 Macro
'
'
Range("Q2:T12").Select
Selection.Cut
Sheets("Sheet2").Select
Range("G2").Select
ActiveSheet.Paste
Dim SheetNameToFind As String
SheetNameToFind = ActiveSheet.Range("A1").Value
Dim SheetToFind As Worksheet
Set SheetToFind = Sheets(SheetNameToFind)
SheetToFind.Select 'or SheetToFind.activate
ActiveWorkbook.Names.Add Name:="dynamic_range", RefersTo:="=offset($b$2,0,0,counta($b:$h),5)"
ActiveSheet.Range("dynamic_range").Copy
Sheets("Sheet1").Select
Range("a2").Select
Sheets("Sheet1").Paste
Sheets("UI").Select
Range("A1").Select
End Sub


This macro is triggered by a command button (assign macro)
but when i press the button, it gives runtime error and highlights the following line
Set SheetToFind = Sheets(SheetNameToFind)


Regards
 
thanks mr mike, u've been an unseen help here, i just wanted john to see that file.

but code still gives error when there's a value in cell, run time error is still appearing, i guess that code needs to be changed a bit to get results, because it was working fine before i merged these two codes
 
Upvote 0

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.

Forum statistics

Threads
1,224,587
Messages
6,179,734
Members
452,939
Latest member
WCrawford

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