M
magmike
I have a macro that takes a named range (New_Row), copies it and inserts itabove the current selection. It is called by a command button. As part of the macro, it sends the focus back to the original sheet (Orders) as the template row is on a different sheet.
But now, I want to use this command button on other sheets. However, it sends the user back to Orders, instead of the present sheet. How could I retrieve the name of the current sheet and then use it in my Macro? (Code below)
Sub Nsert_TemplateRow()
Dim Msg, Style, Title, Response
Msg = "This will insert a New Row ABOVE your currently selected cell. Do you wish to continue?"
Style = vbYesNo + vbInformation
Title = "Insert Row"
Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then
If Selection.Column = 1 Then
Selection.Insert
Sheets("Sheet1").Select
Range("New_Row").Select
Selection.Copy
Sheets("Orders").Select
ActiveSheet.Paste
Else
MsgBox "You must first select a cell in column A", vbInformation, Title
End If
Else
End If
End Sub
Thanks in advance for your help,
magmike
PS: I am open to suggestions on a better way to write the whole of it also,but still would like to know how to pull the name of the sheet and use it elsewhere.
I had tried the following which worked in another workbook, but it will notin this one. Not sure why, but it the error says something about not beingable to insert a row (it is a themed table - could that have something to do with it?)
'Range("New_Row").Copy
'Selection.Insert Shift:=xlDown
'Application.CutCopyMode = False
msk
But now, I want to use this command button on other sheets. However, it sends the user back to Orders, instead of the present sheet. How could I retrieve the name of the current sheet and then use it in my Macro? (Code below)
Sub Nsert_TemplateRow()
Dim Msg, Style, Title, Response
Msg = "This will insert a New Row ABOVE your currently selected cell. Do you wish to continue?"
Style = vbYesNo + vbInformation
Title = "Insert Row"
Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then
If Selection.Column = 1 Then
Selection.Insert
Sheets("Sheet1").Select
Range("New_Row").Select
Selection.Copy
Sheets("Orders").Select
ActiveSheet.Paste
Else
MsgBox "You must first select a cell in column A", vbInformation, Title
End If
Else
End If
End Sub
Thanks in advance for your help,
magmike
PS: I am open to suggestions on a better way to write the whole of it also,but still would like to know how to pull the name of the sheet and use it elsewhere.
I had tried the following which worked in another workbook, but it will notin this one. Not sure why, but it the error says something about not beingable to insert a row (it is a themed table - could that have something to do with it?)
'Range("New_Row").Copy
'Selection.Insert Shift:=xlDown
'Application.CutCopyMode = False
msk