Using loop or if statement to confirm i have selected all the selection i need?

holycome99

New Member
Joined
Nov 16, 2020
Messages
15
Office Version
  1. 365
Platform
  1. 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(n).Activate
If n = wscount Then
Exit For
End If
-----------------
1627275023225.png

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:
1627275088850.png


It is possible to let the vba confirming that they have copied the whole useful data and have them copied to the "sheet2"?
Thanks!
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Replace these lines of code
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
With
VBA Code:
Range("E11:H" & Cells(Rows.Count, "H").End(xlUp).Row - 1).Select
 
Upvote 0

Forum statistics

Threads
1,214,940
Messages
6,122,356
Members
449,080
Latest member
Armadillos

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top