Glasgowsmile
Active Member
- Joined
- Apr 14, 2018
- Messages
- 280
- Office Version
- 365
- Platform
- Windows
Hello,
Some context for this issue. I am trying to move over this whole VBA code to my personal book that is stored in XLSTART and run the macros off that moving forward instead of having them in the reports themself. The code below works fine in the document on its own but doesn't work when I get to the If Not IsEmpty section on the Personal book macro.
I figure I need to target the excel workbooks more directly since I'm using the personal book, which I don't fully know how to do. I tried adding the below code to the Empty formula but it doesn't work. Any help or insight would be greatly appreciated!
Some context for this issue. I am trying to move over this whole VBA code to my personal book that is stored in XLSTART and run the macros off that moving forward instead of having them in the reports themself. The code below works fine in the document on its own but doesn't work when I get to the If Not IsEmpty section on the Personal book macro.
I figure I need to target the excel workbooks more directly since I'm using the personal book, which I don't fully know how to do. I tried adding the below code to the Empty formula but it doesn't work. Any help or insight would be greatly appreciated!
VBA Code:
If Not IsEmpty(MBook.Sheet2.Range("A6").Value) Then
VBA Code:
Sub Import()
Application.DisplayAlerts = False
Dim MBook As Workbook
Dim IBook As Workbook
Dim sh As Worksheet, ws As Worksheet
Dim rg1 As Variant
Dim r1 As Long, c1 As Long
Set MBook = ActiveWorkbook
Set sh = MBook.Sheets(1)
With Application.FileDialog(msoFileDialogOpen)
.Filters.Clear
.Filters.Add "Excel 2007-13", "*.xlsx; *.xls; *.xlsm; *.xlsa; *.csv"
.AllowMultiSelect = False
.Show
If .SelectedItems.Count > 0 Then
Workbooks.Open .SelectedItems(1)
Set IBook = ActiveWorkbook
Set ws = IBook.Sheets(1)
If Not IsEmpty(Sheet2.Range("A6").Value) Then
Sheet3.Range("A1:S400").ClearContents
Sheet2.Range("A1:S400").Copy
Sheet3.Range("A1").PasteSpecial xlPasteValues
Sheet2.Range("A1:S400").ClearContents
End If
With ws
rg1 = .Range("A1:S400").Value
r1 = UBound(rg1): c1 = UBound(rg1, 2)
End With
With sh
Sheet2.Range("A1").Resize(r1, c1).Value = rg1
End With
IBook.Close False
End If
End With
Sheet1.Select
Application.CutCopyMode = False
End Sub
Last edited: