Amit Punia
Member
Need a VBA code which can copy text/numbers/anything from all the cells of first column of all the sheets and paste them in the last sheet in column A. If there are blank cells in between then those blank cells should be deleted in the last sheet called "Consolidated". Like in the first sheet called "Cover" is having numbers in column A starting from cell A4 and the number is 49. So the VBA should copy everything from column A of this sheet and it should paste it in the last sheet called "Consolidated. Once done it should delete all the blank cells in between and then start copying the data from column A of next sheet called "Disclaimer" and paste the data in column A of "Consolidated" sheet just below the existing data.
I checked online and merged 2-3 codes together to do the same but it's not giving out the desired output. Can anybody modify the below mentioned code or provide a new sets of codes for this task.
The file is also attached in this post. I searched the code keeping in mind that Consolidated sheet already exists in the workbook. Is it possible the the code automatically adds a new worksheet, renames it "Consolidated" and pastes all the data from column A of all the other sheets.
Thanks in advance
I checked online and merged 2-3 codes together to do the same but it's not giving out the desired output. Can anybody modify the below mentioned code or provide a new sets of codes for this task.
Code:
Sub Create_Summary()
Dim sh As Worksheet, sumSht As Worksheet
Dim i As Long
Set sumSht = Sheets("Consolidated")
sumSht.Move after:=Worksheets(Worksheets.Count)
For i = 1 To Worksheets.Count - 1 ' once you moved "Consolidated" sheet as the workbook last one, you skip it by limiting loop to the penultimate sheets index
Worksheets(i).Range("A:A").Copy Destination:=sumSht.Cells(1, sumSht.Columns.Count).End(xlToLeft).Offset(, 1) ' qualify all destination references to "Consolidated" sheet
Next i
sumSht.Columns(1).Delete ' "Consolidated" sheet first column gest skipped by the above loop, so delete it
On Error Resume Next
Dim j As Long, ws As Worksheet, rngCopy As Range, rngEnd As Range
Set ws = ActiveSheet
Do Until ws.Cells(1, 2).Value = ""
Set rngCopy = ws.Range("B2", ws.Cells(ws.Rows.Count, "B").End(xlUp))
Set rngEnd = ws.Cells(ws.Rows.Count, "A").End(xlUp).Offset(1, 0)
rngEnd.Resize(rngCopy.Rows.Count, 1).Value = rngCopy.Value
rngCopy.EntireColumn.Delete
Loop
Worksheets("Consolidated").Range("A:A").Select
Selection.SpecialCells(xlCellTypeBlanks).EntireRow.Delete
Range("A1").Select
End Sub
The file is also attached in this post. I searched the code keeping in mind that Consolidated sheet already exists in the workbook. Is it possible the the code automatically adds a new worksheet, renames it "Consolidated" and pastes all the data from column A of all the other sheets.
Thanks in advance
Attachments
Last edited by a moderator: