Working with blank worksheets using IF Then Statements in VBA

JJS

Board Regular
Joined
Jul 8, 2009
Messages
81
Hi me again....


My boss really needs to learn how to do this himself, but that is a different forum I think....:laugh:

I need to take 12 individual workbooks and combine them into one, that in itself is not an issue, been doing that with another set of workbooks for a while now. What is different is that some of these workbooks maybe empty but a check on them needs to be performed to see if there is data before combining data.

On top of this, the "master" workbook is purged and rebuilt with every macro run so I am trying to include conditions that essentially say if the worksheet is empty (blank) then paste the data into cell A2 and append the rest below that. However if the master worksheet is not blank (ie some other person's data has been the first) then find the last occupied row and offset one down then paste to append.

What I have currently looks like this:

Code:
Application.ScreenUpdating = False
    Application.EnableEvents = False
    Application.DisplayAlerts = False
    Application.Calculation = xlCalculationManual
Dim wbOpen As Workbook


 strWbk = "C:\Documents and Settings\user\Desktop\Opportunistic Plays\Opportunistic Plays- Matt"
 Set wbOpen = Workbooks.Open(strWbk)
wbOpen.Sheets(1).Select
ActiveSheet.Unprotect

If ActiveSheet.AutoFilterMode Then
     ActiveSheet.AutoFilterMode = False
End If
  If ActiveSheet.UsedRange.Address = "$A$3" And Range("A3") = "" Then
  wbOpen.Close
End If
    ActiveSheet.UsedRange.Offset(2, 0).Cells.SpecialCells(xlCellTypeVisible).Select
   Selection.Copy

Windows("Opportunistic Plays- MASTER.xls").Activate
Worksheets("Opportunistic Play Master").Select


If Sheets(1).UsedRange.Address = "$A$2" And Range("A2") = "" Then
Range("A2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False

 Else
 Range("A1").Select
 Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Select

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Selection.End(xlDown).Select

 End If
  wbOpen.Close

I have run this in break mode and it copies the data, but does not want to paste it in the master sheet, any help to get this running would be greatly appreciated!


Jeff
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.

Forum statistics

Threads
1,224,884
Messages
6,181,572
Members
453,054
Latest member
arz007

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