Glasgowsmile

Active Member
Joined
Apr 14, 2018
Messages
280
Office Version
  1. 365
Platform
  1. Windows
Good Morning,

I'm using the following code below but ran into a minor issue. It's pulling data from Section2 on another spreadsheet, but sometimes that spreadsheet doesn't have Section2 and so it causes an error. How can I get the code to ignore the error or ignore this code if the spreadsheet doesn't have a Section2, so it can continue with the other lines of code without issues?

Code:
Cols = Application.CountA(wkbCrntWorkBook.Sheets("AAA Discount").Range("A2:A100")) + 1         Sheets("Section2").Range("B23:B100").Copy wkbCrntWorkBook.Sheets("AAA Discount").Cells(2, Cols)
         wkbCrntWorkBook.Sheets("AAA Discount").Cells(1, Cols).CurrentRegion.EntireColumn.AutoFit
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Try
Code:
Cols = Application.CountA(wkbCrntWorkBook.Sheets("AAA Discount").Range("A2:A100")) + 1
If Evaluate("isref(section2!A1)") Then
   Sheets("Section2").Range("B23:B100").Copy wkbCrntWorkBook.Sheets("AAA Discount").Cells(2, Cols)
End If
   wkbCrntWorkBook.Sheets("AAA Discount").Cells(1, Cols).CurrentRegion.EntireColumn.AutoFit
 
Upvote 0
If I want to upload new data to this, how do I clear Sheet4 of the data in it before uploading new data to it each time?
 
Upvote 0
Like
Code:
Sheets("Sheet4").UsedRange.Clear
 
Upvote 0

Forum statistics

Threads
1,215,409
Messages
6,124,743
Members
449,186
Latest member
HBryant

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