hi
I have X sheets which contain data in a fixed range R5C1:R13C46.
I am trying to create a master tab with the data of each tab.
I plan to import the title line at the end only
I wrote the code below but it always start pasting in the Master tab from row 44.
I am not able to figure out why...
Can someone tell me where the error is because it is kind of driving me crazy ....
Thanks
Shiro
I have X sheets which contain data in a fixed range R5C1:R13C46.
I am trying to create a master tab with the data of each tab.
I plan to import the title line at the end only
I wrote the code below but it always start pasting in the Master tab from row 44.
I am not able to figure out why...
Can someone tell me where the error is because it is kind of driving me crazy ....
Thanks
Shiro
Code:
Sub merge_v2()
Dim sht As Worksheet ', csheet As Worksheet
Dim i As Integer
Dim nbofsheet As Integer
Dim firstcol As Integer
Dim lastcol As Integer
Dim firstrow As Integer
Dim lastrow As Integer
Dim nbofrows As Integer
Dim masterarr() As Variant 'Master array to copy
Application.ScreenUpdating = false
firstcol = 1
lastcol = 13
firstrow = 5
lastrow = 46 'total row is 46 but we skip the 4 first rows
nbofrows = lastrow - firstrow + 1
Application.DisplayAlerts = False
On Error Resume Next
Worksheets("Master").Delete
On Error GoTo 0
Application.DisplayAlerts = True
Worksheets.Add(After:=Sheets(Sheets.Count)).Name = "Master"
Sheets("Master").Cells(1, 15).Value = Format(Now(), "dd-mmmm-yy h:mm:ss")
Cells(1, 1).Activate
nbofsheet = ThisWorkbook.Worksheets.Count - 1
i = 0
For Each sht In ActiveWorkbook.Worksheets
If sht.Visible Then
If sht.Name <> "Master" Then
sht.Activate
sht.Range(Cells(firstrow, firstcol), Cells(lastrow, lastcol)).Copy
Sheets("Master").Cells((i * nbofrows) + 1, 1).PasteSpecial 'xlPasteValues
Application.CutCopyMode = False
'
i = i + 1
End If
sht.Activate
End If
Cells(1, 1).Activate
Next sht
Sheets("Master").cells(1,1).Activate
Application.ScreenUpdating = True
End Sub