Nlhicks
Active Member
- Joined
- Jan 8, 2021
- Messages
- 264
- Office Version
- 365
- Platform
- Windows
Sub FindRightRow1()
'Call NewestFile("c:\\Documents\Ratings\")
Application.ScreenUpdating = False
Dim LineUpdate As Worksheet, Sheet2 As Worksheet
Dim Ws As Range
Dim Rowz As Integer
Dim Wb As Workbook
Windows("WAPA-UGPR Facility Rating and SOL Record (Master).xlsm").Activate
This code works when I have both workbooks open and the names do not change. However, when I finish running this full code I save the workbook with the next version number so it will become v160.
I want to open the latest version and have this code work on that version. How can I make it so that version numbers do not matter in the workbook name?
Sheets("Line Update").Activate
Set LineUpdate = Sheets("Line Update")
Set Wb = Workbooks.Open("WAPA-UGPR Facility Rating and SOL Record (Data File)_v159.xlsx")
Wb.Sheets("Facility Ratings & SOLs (Lines)").Activate
Set Sheet2 = Sheets("Facility Ratings & SOLs (Lines)")
Set Ws = Sheet2.UsedRange
With Sheet2.Range("A1")
If LineUpdate.Range("D5").Value <> "" Then
Sheets("Facility Ratings & SOLs (Lines)").Activate
.AutoFilter field:=10, Criteria1:="*" & LineUpdate.Range("D5") & "*"
End If
If LineUpdate.Range("D6").Value <> "" Then
.AutoFilter field:=11, Criteria1:="*" & LineUpdate.Range("D6") & "*"
End If
If LineUpdate.Range("D7").Value <> "" Then
.AutoFilter field:=37, Criteria1:="" & LineUpdate.Range("D7") & ""
End If
Rowz = Application.WorksheetFunction.Subtotal(3, Range("A2:A686" & Rows(Rows.Count).End(xlUp).Row))
Debug.Print Rowz
'
If Rowz <= 1 Then
LineUpdate.Range("C11").Value = Wb.Sheets("Facility Ratings & SOLs (Lines)").Range("B2:B695").SpecialCells(xlCellTypeVisible)
LineUpdate.Range("C12").Value = Wb.Sheets("Facility Ratings & SOLs (Lines)").Range("C2:C695").SpecialCells(xlCellTypeVisible)
LineUpdate.Range("C13").Value = Wb.Sheets("Facility Ratings & SOLs (Lines)").Range("D2:D695").SpecialCells(xlCellTypeVisible)
LineUpdate.Range("C14").Value = Wb.Sheets("Facility Ratings & SOLs (Lines)").Range("E2:E695").SpecialCells(xlCellTypeVisible)
LineUpdate.Range("C15").Value = Wb.Sheets("Facility Ratings & SOLs (Lines)").Range("F2:F695").SpecialCells(xlCellTypeVisible)
LineUpdate.Range("C16").Value = Wb.Sheets("Facility Ratings & SOLs (Lines)").Range("G2:G695").SpecialCells(xlCellTypeVisible)
LineUpdate.Range("C17").Value = Wb.Sheets("Facility Ratings & SOLs (Lines)").Range("H2:H695").SpecialCells(xlCellTypeVisible)
LineUpdate.Range("C18").Value = Wb.Sheets("Facility Ratings & SOLs (Lines)").Range("I2:I695").SpecialCells(xlCellTypeVisible)
GoTo Skip
ElseIf Rowz > 1 Then GoSub Item_Open
Wb.Sheets("Facility Ratings & SOLs (Lines)").Activate
.AutoFilter field:=36, Criteria1:=LineUpdate.Range("H6")
LineUpdate.Range("C11").Value = Wb.Sheets("Facility Ratings & SOLs (Lines)").Range("B2:B695").SpecialCells(xlCellTypeVisible)
LineUpdate.Range("C12").Value = Wb.Sheets("Facility Ratings & SOLs (Lines)").Range("C2:C695").SpecialCells(xlCellTypeVisible)
LineUpdate.Range("C13").Value = Wb.Sheets("Facility Ratings & SOLs (Lines)").Range("D2:D695").SpecialCells(xlCellTypeVisible)
LineUpdate.Range("C14").Value = Wb.Sheets("Facility Ratings & SOLs (Lines)").Range("E2:E695").SpecialCells(xlCellTypeVisible)
LineUpdate.Range("C15").Value = Wb.Sheets("Facility Ratings & SOLs (Lines)").Range("F2:F695").SpecialCells(xlCellTypeVisible)
LineUpdate.Range("C16").Value = Wb.Sheets("Facility Ratings & SOLs (Lines)").Range("G2:G695").SpecialCells(xlCellTypeVisible)
LineUpdate.Range("C17").Value = Wb.Sheets("Facility Ratings & SOLs (Lines)").Range("H2:H695").SpecialCells(xlCellTypeVisible)
LineUpdate.Range("C18").Value = Wb.Sheets("Facility Ratings & SOLs (Lines)").Range("I2:I695").SpecialCells(xlCellTypeVisible)
Skip:
End If
End With
Exit Sub
Item_Open:
Dim sValue As String
Windows("WAPA-UGPR Facility Rating and SOL Record (Master).xlsm").Activate
Sheets("Line Update").Activate
sValue = Application.InputBox("Enter the TO: Bus Number here, Thank you.")
Worksheets("Line Update").Range("H6").Value = sValue
Debug.Print sValue
Return
Application.ScreenUpdating = True
End Sub
'Call NewestFile("c:\\Documents\Ratings\")
Application.ScreenUpdating = False
Dim LineUpdate As Worksheet, Sheet2 As Worksheet
Dim Ws As Range
Dim Rowz As Integer
Dim Wb As Workbook
Windows("WAPA-UGPR Facility Rating and SOL Record (Master).xlsm").Activate
This code works when I have both workbooks open and the names do not change. However, when I finish running this full code I save the workbook with the next version number so it will become v160.
I want to open the latest version and have this code work on that version. How can I make it so that version numbers do not matter in the workbook name?
Sheets("Line Update").Activate
Set LineUpdate = Sheets("Line Update")
Set Wb = Workbooks.Open("WAPA-UGPR Facility Rating and SOL Record (Data File)_v159.xlsx")
Wb.Sheets("Facility Ratings & SOLs (Lines)").Activate
Set Sheet2 = Sheets("Facility Ratings & SOLs (Lines)")
Set Ws = Sheet2.UsedRange
With Sheet2.Range("A1")
If LineUpdate.Range("D5").Value <> "" Then
Sheets("Facility Ratings & SOLs (Lines)").Activate
.AutoFilter field:=10, Criteria1:="*" & LineUpdate.Range("D5") & "*"
End If
If LineUpdate.Range("D6").Value <> "" Then
.AutoFilter field:=11, Criteria1:="*" & LineUpdate.Range("D6") & "*"
End If
If LineUpdate.Range("D7").Value <> "" Then
.AutoFilter field:=37, Criteria1:="" & LineUpdate.Range("D7") & ""
End If
Rowz = Application.WorksheetFunction.Subtotal(3, Range("A2:A686" & Rows(Rows.Count).End(xlUp).Row))
Debug.Print Rowz
'
If Rowz <= 1 Then
LineUpdate.Range("C11").Value = Wb.Sheets("Facility Ratings & SOLs (Lines)").Range("B2:B695").SpecialCells(xlCellTypeVisible)
LineUpdate.Range("C12").Value = Wb.Sheets("Facility Ratings & SOLs (Lines)").Range("C2:C695").SpecialCells(xlCellTypeVisible)
LineUpdate.Range("C13").Value = Wb.Sheets("Facility Ratings & SOLs (Lines)").Range("D2:D695").SpecialCells(xlCellTypeVisible)
LineUpdate.Range("C14").Value = Wb.Sheets("Facility Ratings & SOLs (Lines)").Range("E2:E695").SpecialCells(xlCellTypeVisible)
LineUpdate.Range("C15").Value = Wb.Sheets("Facility Ratings & SOLs (Lines)").Range("F2:F695").SpecialCells(xlCellTypeVisible)
LineUpdate.Range("C16").Value = Wb.Sheets("Facility Ratings & SOLs (Lines)").Range("G2:G695").SpecialCells(xlCellTypeVisible)
LineUpdate.Range("C17").Value = Wb.Sheets("Facility Ratings & SOLs (Lines)").Range("H2:H695").SpecialCells(xlCellTypeVisible)
LineUpdate.Range("C18").Value = Wb.Sheets("Facility Ratings & SOLs (Lines)").Range("I2:I695").SpecialCells(xlCellTypeVisible)
GoTo Skip
ElseIf Rowz > 1 Then GoSub Item_Open
Wb.Sheets("Facility Ratings & SOLs (Lines)").Activate
.AutoFilter field:=36, Criteria1:=LineUpdate.Range("H6")
LineUpdate.Range("C11").Value = Wb.Sheets("Facility Ratings & SOLs (Lines)").Range("B2:B695").SpecialCells(xlCellTypeVisible)
LineUpdate.Range("C12").Value = Wb.Sheets("Facility Ratings & SOLs (Lines)").Range("C2:C695").SpecialCells(xlCellTypeVisible)
LineUpdate.Range("C13").Value = Wb.Sheets("Facility Ratings & SOLs (Lines)").Range("D2:D695").SpecialCells(xlCellTypeVisible)
LineUpdate.Range("C14").Value = Wb.Sheets("Facility Ratings & SOLs (Lines)").Range("E2:E695").SpecialCells(xlCellTypeVisible)
LineUpdate.Range("C15").Value = Wb.Sheets("Facility Ratings & SOLs (Lines)").Range("F2:F695").SpecialCells(xlCellTypeVisible)
LineUpdate.Range("C16").Value = Wb.Sheets("Facility Ratings & SOLs (Lines)").Range("G2:G695").SpecialCells(xlCellTypeVisible)
LineUpdate.Range("C17").Value = Wb.Sheets("Facility Ratings & SOLs (Lines)").Range("H2:H695").SpecialCells(xlCellTypeVisible)
LineUpdate.Range("C18").Value = Wb.Sheets("Facility Ratings & SOLs (Lines)").Range("I2:I695").SpecialCells(xlCellTypeVisible)
Skip:
End If
End With
Exit Sub
Item_Open:
Dim sValue As String
Windows("WAPA-UGPR Facility Rating and SOL Record (Master).xlsm").Activate
Sheets("Line Update").Activate
sValue = Application.InputBox("Enter the TO: Bus Number here, Thank you.")
Worksheets("Line Update").Range("H6").Value = sValue
Debug.Print sValue
Return
Application.ScreenUpdating = True
End Sub