holycome99
New Member
- Joined
- Nov 16, 2020
- Messages
- 15
- Office Version
- 365
- Platform
- Windows
I got a excel file that contain a number of invoice sheet (~30), and my task is to consolidate them into a single sheet, and at the same time removing the useless data.
I found that the cell E11 must be the first containing the useful information, and using E11, I can use ctrl and shift selection to have all the useful information contained.
And so, I made these coding for it:
---------------
Dim ws As Worksheet, a As Range
Dim rowcount As Long
Dim n As Integer
Dim wscount As Integer
wscount = ThisWorkbook.Sheets.Count
n = 1
For Each ws In ActiveWorkbook.Worksheets
Range("E11").Select
If IsEmpty(Range("E11")) Then
Exit For
End If
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
Sheets("Sheet2").Select
rowcount = Cells(Rows.Count, 1).End(xlUp).Row
Cells(rowcount + 1, 1).Select
ActiveSheet.Paste
ActiveSheet.Paste Link:=True
n = n + 1
Worksheets.Activate
If n = wscount Then
Exit For
End If
-----------------
if it was in good situation, it would be appear sth like that.
But sometime, if some of the data were missing, then it will appear like this:
It is possible to let the vba confirming that they have copied the whole useful data and have them copied to the "sheet2"?
Thanks!
I found that the cell E11 must be the first containing the useful information, and using E11, I can use ctrl and shift selection to have all the useful information contained.
And so, I made these coding for it:
---------------
Dim ws As Worksheet, a As Range
Dim rowcount As Long
Dim n As Integer
Dim wscount As Integer
wscount = ThisWorkbook.Sheets.Count
n = 1
For Each ws In ActiveWorkbook.Worksheets
Range("E11").Select
If IsEmpty(Range("E11")) Then
Exit For
End If
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
Sheets("Sheet2").Select
rowcount = Cells(Rows.Count, 1).End(xlUp).Row
Cells(rowcount + 1, 1).Select
ActiveSheet.Paste
ActiveSheet.Paste Link:=True
n = n + 1
Worksheets.Activate
If n = wscount Then
Exit For
End If
-----------------
if it was in good situation, it would be appear sth like that.
But sometime, if some of the data were missing, then it will appear like this:
It is possible to let the vba confirming that they have copied the whole useful data and have them copied to the "sheet2"?
Thanks!