I am attempting to add a new sheet after a specific sheet. Best I can remember (it has been some time back), it worked in standalone mode in a short test macro but now that I have integrated the code below with the rest of the macro code, it is not working. It compiles fine but at runtime, it errors out - error screenshot below. To debug, I put the code in a test macro, as noted below. Again, it still errors out on the same NOTED line of code. I cannot for the life of me figure this one out.
I am also wide open to any code cleanup that is offered to improve flow, make it run faster, or anything else of the sort.
PLEASE HELP!!!
-----------------------------------------------------------------------------------------------------------------------------
Error Screenshot
I am also wide open to any code cleanup that is offered to improve flow, make it run faster, or anything else of the sort.
PLEASE HELP!!!
-----------------------------------------------------------------------------------------------------------------------------
VBA Code:
Sub test()
Dim LastName As String
Dim FirstName As String
Dim FullName As String
Sheets("Patient").Select
LastName = "ALast1" 'this is a dummy line to set the variable in the test macro
FirstName = "AFirst1"' this is a dummy line to set the variable in the test macro
FullName = LastName & ", " & FirstName
Sheets.Add After:=Sheets("DON'T REMOVE THIS TAB2").Name = FullName '<-----------------------THIS IS THE LINE THAT THROWS THE SCREENSHOTTED ERROR BELOW
Worksheets("LOG TAB MASTER").Range("a1:XFD1048576").Copy
ActiveSheet.Paste Destination:=Worksheets(LastName & ", " & FirstName) _
.Range("a1:XFD1048576")
Sheets(LastName & ", " & FirstName).Select
With ActiveWorkbook.Sheets(LastName & ", " & FirstName).Tab _
.ColorIndex = xlColorIndexNone
End With
End Sub
Error Screenshot
VBA Code:
Last edited by a moderator: