I am trying to speed up my code by re-writing it not using select.
I have three tabs, and I want to paste the tab name next to the data that appears in that respective tab, without selecting the tab.
However, I am finding that when I run the code, say for example on sheet 1, it works for sheet 1 but when it trys to do the same for sheet 2 it fails with error "Run-time error '1004': Application-defined or object-defined error."
Please see below my code.
Sub Create_Reports_NEWWWW()
Application.ScreenUpdating = False
Dim wb As Workbook
Dim LastRow As Integer
Dim LastColumn As Integer
Set wb = ActiveWorkbook
'copy sheet name to right of raw data on each sheet
LastRow = wb.Sheets(1).Cells(Rows.Count, 1).End(xlUp).Row
LastColumn = wb.Sheets(1).Cells(4, Columns.Count).End(xlToLeft).Column
wb.Sheets(1).Range(Cells(4, LastColumn + 1), Cells(LastRow, LastColumn + 1)) = wb.Sheets(1).Name
LastRow = wb.Sheets(2).Cells(Rows.Count, 1).End(xlUp).Row
LastColumn = wb.Sheets(2).Cells(4, Columns.Count).End(xlToLeft).Column
wb.Sheets(2).Range(Cells(4, LastColumn + 1), Cells(LastRow, LastColumn + 1)) = wb.Sheets(2).Name
LastRow = wb.Sheets(3).Cells(Rows.Count, 1).End(xlUp).Row
LastColumn = wb.Sheets(3).Cells(4, Columns.Count).End(xlToLeft).Column
wb.Sheets(3).Range(Cells(4, LastColumn + 1), Cells(LastRow, LastColumn + 1)) = wb.Sheets(3).Name