I'm using Excel 2013 and new to VBA. I created a macro that served it's purpose with no errors. I then created a form control button and assigned the macro. tested it, worked great with no issues. Then I did two things before realizing the button is no longer working. 1st I used this code
Private Sub Worksheet_Change(ByVal Target As Range)
Dim KeyCells As Range
Dim ws As Worksheet
Set KeyCells = Range("P1")
If Not Application.Intersect(KeyCells, Range(Target.Address)) _
Is Nothing Then
For Each ws In ThisWorkbook.Sheets
If ws.Name <> "CLOSING RPD" Then
ws.Name = Format(ws.Range("A2"), "ddd, d")
End If
Next ws
MsgBox "This workbook has been updated.", vbOKOnly, "ALL DONE"
End If
End Sub
on sheet1 and tested it. It worked with 1 issue, if the tab name already exists. I was going to add a line to handle the error but had other items to attend to first.
then I renamed the module containing the macro used for the form control button.
Now when I click on the button I get this: "Cannot run the macro "template V5.xlsm'!Copy Sheet Data to Closing RPD". The macro my not be available in this workbook or all macros may be disabled.
"template V5" is the workbook name and the macro is called "Copy_Paste_specal_Values"
"Copy sheet data to closing RPD" is the caption in the button.
Please help me understand how I managed to break everything in this workbook and if I can fix it.
Thank you for taking the time to read my issue. This is my first post on this forum.
How I solved it:
I am still unaware of the specific cause, however deleting all of the form control buttons, (I had 1 per sheet), creating new ones and creating a macro for each as opposed to my previous method, which was using the same macro on every button running this code
Sub Copy_Paste_to_CLOSING_RPD()
Dim Response As Integer
Response = MsgBox(prompt:="You are about to copy this worksheet to the CLOSING RPD tab. Click 'Yes' to continue, or 'No' to cancel the operation.", Buttons:=vbYesNo, Title:="ARE YOU SURE?")
If Response = vbYes Then
Range("B2").Select
Selection.End(xlDown).Offset(1, -1).Select
Range(ActiveCell, Cells(ActiveCell.Row + 43, 8)).Select
Selection.Delete Shift:=xlUp
Range("A2").Select
Application.CutCopyMode = False
Range("A2:H" & Range("A1000").End(xlUp).Row).Cop
Worksheets("CLOSING RPD").Activate
Range("A" & Range("A65500").End(xlUp).Row + 1).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Range("A2").Select
Else
MsgBox "No data has been copied.", vbOKOnly, "CANCELLED"
End If
End Sub
Now I have that code (31) times. 1 for each day of the month, with the sheet name added at the end for each. again I don't know what caused this which was half the reason for this post. If anyone else runs into this issue, please post the circumstances here.
I'm sure if this code above were more efficient, then I would not have run into the error mentioned at the beginning of the post.
Bookmarks