Macro to continue if there is no data to select in a workbook

LouLee

New Member
Joined
Aug 17, 2013
Messages
4
Hi, I have a macro that pulls in data from many workbooks. If there is no data in one of the workbooks the macro will not continue. Is there a loop or some other coding I need. The code for one of the worksheets is: (I am new to excel and know there must be parts that can be deleted in the below :rolleyes: Workbooks.Open Filename:= _
"J:\SPORTSFORCE\SPORTSFORCE BUSINESS PLANS\Reporting spreadsheet\Cricket.xlsx"
Sheets("Numbers Report ").Select
ActiveSheet.Outline.ShowLevels RowLevels:=2
Range("A6").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Rows.Ungroup
Columns("B:B").Select
Selection.SpecialCells(xlCellTypeBlanks).Select
Selection.EntireRow.Delete
Range("A1:DJ1").Select
ActiveCell.Offset(1, 0).Range("A1:DJ1").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
ThisWorkbook.Activate
Sheets("Numbers Report ").Select
Range("A18").Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveSheet.Paste
Range("A18").Select
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
I might be reading this wrong, and I don't have Excel at the moment, so it's UNTESTED, but try

Code:
Dim lr As Long
lr = Cells(Rows.Count, "A").End(xlUp).Row
Workbooks.Open Filename:="J:\SPORTSFORCE\SPORTSFORCE BUSINESS PLANS\Reporting spreadsheet\Cricket.xlsx"
Sheets("Numbers Report ").Outline.ShowLevels RowLevels:=2
ActiveSheet.UsedRange.Rows.Ungroup
Columns("B:B").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
On Error Resume Next
Range("A1:DJ1").Copy Destination:=Range("A" & lr + 1)
lr = Cells(Rows.Count, "A").End(xlUp).Row
 
Upvote 0
I might be reading this wrong, and I don't have Excel at the moment, so it's UNTESTED, but try

Code:
Dim lr As Long
lr = Cells(Rows.Count, "A").End(xlUp).Row
Workbooks.Open Filename:="J:\SPORTSFORCE\SPORTSFORCE BUSINESS PLANS\Reporting spreadsheet\Cricket.xlsx"
Sheets("Numbers Report ").Outline.ShowLevels RowLevels:=2
ActiveSheet.UsedRange.Rows.Ungroup
Columns("B:B").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
On Error Resume Next
Range("A1:DJ1").Copy Destination:=Range("A" & lr + 1)
lr = Cells(Rows.Count, "A").End(xlUp).Row

Thank you Michael, I will try this when I get to work, after it runs through this Cricket workbook it pastes the data in the Main book, then it goes to the next sport.xlsx workbook and does the same as above. Will it need that same 'On Error Resume Next' if there is nothing to paste into the Main Book? Thanks again for the time you spent helping me I will let you know how I get on.
 
Upvote 0
Great outcome thanks.

Thank you Michael, I will try this when I get to work, after it runs through this Cricket workbook it pastes the data in the Main book, then it goes to the next sport.xlsx workbook and does the same as above. Will it need that same 'On Error Resume Next' if there is nothing to paste into the Main Book? Thanks again for the time you spent helping me I will let you know how I get on.
 
Upvote 0

Forum statistics

Threads
1,215,872
Messages
6,127,437
Members
449,382
Latest member
DonnaRisso

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