sspatriots
Well-known Member
- Joined
- Nov 22, 2011
- Messages
- 585
- Office Version
- 365
- Platform
- Windows
Hi,
I have this macro that I pieced together this morning from another macro. Basically, it temporarily opens another workbook and copies 4 different ranges of table columns back into back into a different table on my destination workbook where the macro resides. The last column defined in "My_Range1" is called "Job Status" (with a carriage return after Job, hence the use of "Chr(10)" in between). Anyhow, I would like to know if it is possible to filter that whole source worksheet for two values in that "Job Status" column prior to bringing the column information into the destination workbook. The values would be "0 NEW" and "1 ACT". Any assistance on this would be greatly appreciated. Thanks, SS
I have this macro that I pieced together this morning from another macro. Basically, it temporarily opens another workbook and copies 4 different ranges of table columns back into back into a different table on my destination workbook where the macro resides. The last column defined in "My_Range1" is called "Job Status" (with a carriage return after Job, hence the use of "Chr(10)" in between). Anyhow, I would like to know if it is possible to filter that whole source worksheet for two values in that "Job Status" column prior to bringing the column information into the destination workbook. The values would be "0 NEW" and "1 ACT". Any assistance on this would be greatly appreciated. Thanks, SS
VBA Code:
Sub Refresh_n_ResizePOJobListTable()
Dim wb1, wb2 As Workbook
Dim file_path1 As String
Dim ws1, ws2, ws3, ws4 As Worksheet
Dim rng1 As Range
Dim My_Range1, My_Range2, My_Range3, My_Range4 As Range
Dim tb1 As ListObject
Dim LastRow1 As Long
Dim BlankCount As Long
With Application
.EnableEvents = False
.ScreenUpdating = False
.CutCopyMode = False
.DisplayAlerts = True
.Calculation = xlCalculationManual
End With
Set wb1 = ThisWorkbook
file_path1 = "H:\Jobs\00 ENGINEERING DATA\SPS Job List, 022924.xlsm" 'Path to Job List.xlsm
Set wb2 = Workbooks.Open(Filename:=file_path1, ReadOnly:=True, IgnoreReadOnlyRecommended:=True) 'Job List.xlsm
Set ws1 = wb1.Worksheets("PO Job List")
Set ws2 = wb2.Worksheets("Jobs")
Set tbl = ws1.ListObjects("tblG2JobList")
Set My_Range1 = ws2.Range("G2JobList[[#Data],[Record]:[Job" & Chr(10) & "Status]]")
Set My_Range2 = ws2.Range("G2JobList[[#Data],[G1" & Chr(10) & "Status]:[G1" & Chr(10) & "APPD Date]]")
Set My_Range3 = ws2.Range("G2JobList[[#Data],[G1 MFG" & Chr(10) & "SCHED" & Chr(10) & "Due Date]:[G1" & Chr(10) & "COMPL Date]]")
Set My_Range4 = ws2.Range("G2JobList[[#Data],[Jack" & Chr(10) & "Vendor]:[Wiring" & Chr(10) & "SHPG ARR/" & Chr(10) & "ITEM LCTN]]")
LastRow1 = ws2.Range("G2JobList[#All]").SpecialCells(xlCellTypeLastCell).Row - 1
Set rng1 = ws1.Range("tblG2JobList[#All]").Resize(LastRow1)
tbl.Resize rng1
ws1.Range("tblG2JobList[[#Data],[Record]:[Job" & Chr(10) & "Status]]").Value2 = My_Range1.Value2
ws1.Range("tblG2JobList[[#Data],[G1" & Chr(10) & "Status]:[G1" & Chr(10) & "APPD Date]]").Value2 = My_Range2.Value2
ws1.Range("tblG2JobList[[#Data],[G1 MFG" & Chr(10) & "SCHED" & Chr(10) & "Due Date]:[G1" & Chr(10) & "COMPL Date]]").Value2 = My_Range3.Value2
ws1.Range("tblG2JobList[[#Data],[Jack" & Chr(10) & "Vendor]:[Wiring" & Chr(10) & "SHPG ARR/" & Chr(10) & "ITEM LCTN]]").Value2 = My_Range4.Value2
BlankCount = Application.CountBlank(ws2.ListObjects("G2JobList").ListColumns("Record").DataBodyRange)
If BlankCount = 0 Then GoTo EndOfJobListUpdates
With ws1.Range("tblG2JobList[[#Data],[Record]]").SpecialCells(xlCellTypeBlanks).Delete(xlShiftUp)
End With
EndOfJobListUpdates:
ws1.Activate
ws1.Range("A1").Select
ActiveWindow.ScrollRow = ActiveCell.Row
wb2.Close SaveChanges:=False 'Un-Remark this line of code after all testing is complete, SPS, 02/07/24
With Application
.EnableEvents = True
.ScreenUpdating = True
.CutCopyMode = True
.DisplayAlerts = True
.Calculation = xlCalculationAutomatic
End With
End Sub