Glasgowsmile
Active Member
- Joined
- Apr 14, 2018
- Messages
- 280
- Office Version
- 365
- Platform
- Windows
Good Morning,
I've got coding for a report that works well, minus 1 small issue I'd like to correct.
Currently this code pulls data from another worksheet, pastes it into the active sheet and compares it to another hidden sheet with old data.
Instead of just copying data blindly, I need it to look at the Month on the hidden page and pull that data from the separate spreadsheet instead of just pulling whatever is in the cell range that I currently have listed.
For example: When I move from August to September, the new report I'm pulling from will have September data and the old report will show August data so when they pull and compare, they're comparing two separate months.
I need the report to ignore the august data and look for the September data and pull that instead.
I've got coding for a report that works well, minus 1 small issue I'd like to correct.
Currently this code pulls data from another worksheet, pastes it into the active sheet and compares it to another hidden sheet with old data.
Instead of just copying data blindly, I need it to look at the Month on the hidden page and pull that data from the separate spreadsheet instead of just pulling whatever is in the cell range that I currently have listed.
For example: When I move from August to September, the new report I'm pulling from will have September data and the old report will show August data so when they pull and compare, they're comparing two separate months.
I need the report to ignore the august data and look for the September data and pull that instead.
Code:
Sub FuturePDI() Dim wsPropertySegmentData As Worksheet
Dim wkbSourceBook As Workbook
Dim PasteCopyRange As Range, Area As Range
Dim FileName As String
Set wsPropertySegmentData = ThisWorkbook.Worksheets("Property Segment Data")
Set PasteCopyRange = wsPropertySegmentData.Range("B2:I18,N4:AC18,B21:I34,N21:AC34,B37:I50,N37:AC50")
With Application.FileDialog(msoFileDialogOpen)
.Filters.Clear
.Filters.Add "Excel 2007-13", "*.xlsx; *.xls; *.xlsm; *.xlsa"
.AllowMultiSelect = False
.Show
If .SelectedItems.Count = 0 Then Exit Sub
FileName = .SelectedItems(1)
End With
On Error GoTo myerror
With Application
.ScreenUpdating = False: .EnableEvents = False: .Calculation = xlCalculationManual
End With
PasteCopyRange.Clear
Set wkbSourceBook = Workbooks.Open(FileName, , True)
For Each Area In PasteCopyRange.Areas
wkbSourceBook.Sheets("Property Segment Data").Range(Area.Address).Copy
With Area.Cells(1, 1)
.PasteSpecial xlPasteValues
.PasteSpecial xlPasteFormats
End With
'clear clipboard
Application.CutCopyMode = False
Next Area
wkbSourceBook.Close False
Columns("A").EntireColumn.Hidden = True
Rows("1").EntireRow.Hidden = True
Columns("B").ColumnWidth = 23
Columns("C").ColumnWidth = 28
Columns("N").ColumnWidth = 28
Columns("D:L").ColumnWidth = 11
Columns("O:AC").ColumnWidth = 11
myerror:
With Application
.ScreenUpdating = True: .EnableEvents = True: .Calculation = xlCalculationAutomatic
End With
If Err <> 0 Then MsgBox (Error(Err)), 48, "Error"
End Sub