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
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