Nlhicks
Active Member
- Joined
- Jan 8, 2021
- Messages
- 264
- Office Version
- 365
- Platform
- Windows
This code was working perfectly and now it is not. I have not changed anything on my template and all of a sudden it is giving me this error. Any ideas?
VBA Code:
Sub FindRightRow1()
Dim Rowz As Integer
Dim wb As Workbook
Dim wbMaster As Workbook
Dim wsLinesMaster As Worksheet
Dim wbUpdate As Workbook
Dim wsFacility As Worksheet
Dim sValue As String, tValue As String, uValue As String
Dim strFile As String
Dim strWbVersion As String
Dim Rng1 As Range, Rng2 As Range, myRange As Range
Dim StorRng As Variant
Dim SearchCell As Integer
'//// adjust the path to match, this is my sample for testing \\\'
Const cstrPath As String = "C:\Users\nhicks\Documents\Ratings\Saved Versions\"
Const cstrStFileName As String = "WAPA-UGPR Facility Rating and SOL Record (Data File)_v"
Const cstrwbMaster As String = "WAPA-UGPR Facility Rating and SOL Record (Master).xlsm"
Const cstrMasterUpdate As String = "Line Update"
Const cstrShFacility As String = "Facility Ratings & SOLs (Lines)"
'/// will find any xls, xlsb, xlsx or xlsm workbook that start with cstrStFileName
'/// and should deliver the highest number from there
strWbVersion = HighestVersion(cstrPath, ".xlsm", cstrStFileName)
If Len(strWbVersion) = 0 Then
MsgBox "Could not spot a version of " & vbCrLf & cstrStFileName & _
vbCrLf & "in Path " & cstrPath, vbInformation, cstrMsgTitle
GoTo end_here
End If
For Each wb In Workbooks
If LCase(wb.Name) = LCase(cstrwbMaster) Then
Set wbMaster = wb
Exit For
End If
Next wb
If wbMaster Is Nothing Then
If Dir(cstrwbMaster) <> "" Then
Set wbMaster = Workbooks.Open(cstrwbMaster)
Else
MsgBox "Could not find '" & cstrwbMaster & "' in current folder. Please open workbook and start again.", vbInformation, cstrMsgTitle
GoTo end_here
End If
End If
If Evaluate("ISREF('[" & cstrwbMaster & "]" & cstrMasterUpdate & "'!A1)") Then
Set wsLinesMaster = wbMaster.Sheets(cstrMasterUpdate)
Else
MsgBox "Sheet '" & cstrMasterUpdate & "' not found in workbook '" & cstrwbMaster, vbInformation, cstrMsgTitle
GoTo end_here
End If
For Each wb In Workbooks
If LCase(wb.Name) = LCase(strWbVersion) Then
Set wbUpdate = wb
Exit For
End If
Next wb
If wbUpdate Is Nothing Then
If Dir(IIf(Right(cstrPath, 1) = "\", cstrPath, cstrPath & "\") & strWbVersion) <> "" Then
Set wbUpdate = Workbooks.Open(IIf(Right(cstrPath, 1) = "\", cstrPath, cstrPath & "\") & strWbVersion)
Else
MsgBox "Could not find '" & strWbVersion & "' in " & cstrPath & ". Please open workbook and start again.", vbInformation, cstrMsgTitle
GoTo end_here
End If
End If
If Evaluate("ISREF('[" & strWbVersion & "]" & cstrShFacility & "'!A1)") Then
Set wsFacility = wbUpdate.Sheets(cstrShFacility)
Else
MsgBox "Sheet '" & cstrShFacility & "' not found in workbook '" & strWbVersion, vbInformation, cstrMsgTitle
GoTo end_here
End If
Application.ScreenUpdating = False
With wsFacility
If wsLinesMaster.Range("D5").Value <> "" Then
.Range("A1").CurrentRegion.AutoFilter field:=10, Criteria1:="*" & wsLinesMaster.Range("D5") & "*"
End If
If wsLinesMaster.Range("D6").Value <> "" Then
.Range("A1").CurrentRegion.AutoFilter field:=11, Criteria1:="*" & wsLinesMaster.Range("D6") & "*"
End If
If wsLinesMaster.Range("D7").Value <> "" Then
.Range("A1").CurrentRegion.AutoFilter field:=37, Criteria1:="" & wsLinesMaster.Range("D7") & ""
End If
Rowz = Application.WorksheetFunction.Subtotal(3, .Range("A2:A" & .Cells(.Rows.Count, "A").End(xlUp).Row))
Debug.Print Rowz
If Rowz <= 1 Then
wsLinesMaster.Range("C11").Value = .Range("B2:B695").SpecialCells(xlCellTypeVisible)
wsLinesMaster.Range("C12").Value = .Range("C2:C695").SpecialCells(xlCellTypeVisible)
wsLinesMaster.Range("C13").Value = .Range("D2:D695").SpecialCells(xlCellTypeVisible)
wsLinesMaster.Range("C14").Value = .Range("E2:E695").SpecialCells(xlCellTypeVisible)
wsLinesMaster.Range("C15").Value = .Range("F2:F695").SpecialCells(xlCellTypeVisible)
wsLinesMaster.Range("C16").Value = .Range("G2:G695").SpecialCells(xlCellTypeVisible)
wsLinesMaster.Range("C17").Value = .Range("H2:H695").SpecialCells(xlCellTypeVisible)
wsLinesMaster.Range("C18").Value = .Range("I2:I695").SpecialCells(xlCellTypeVisible)
If IsEmpty(Range("C11")) Then
Call Reverse
End If
ElseIf Rowz > 1 Then
GoSub Item_Open
.Range("A1").CurrentRegion.AutoFilter field:=36, Criteria1:=wsLinesMaster.Range("H6")
wsLinesMaster.Range("C11").Value = .Range("B2:B695").SpecialCells(xlCellTypeVisible)
wsLinesMaster.Range("C12").Value = .Range("C2:C695").SpecialCells(xlCellTypeVisible)
wsLinesMaster.Range("C13").Value = .Range("D2:D695").SpecialCells(xlCellTypeVisible)
wsLinesMaster.Range("C14").Value = .Range("E2:E695").SpecialCells(xlCellTypeVisible)
wsLinesMaster.Range("C15").Value = .Range("F2:F695").SpecialCells(xlCellTypeVisible)
wsLinesMaster.Range("C16").Value = .Range("G2:G695").SpecialCells(xlCellTypeVisible)
wsLinesMaster.Range("C17").Value = .Range("H2:H695").SpecialCells(xlCellTypeVisible)
wsLinesMaster.Range("C18").Value = .Range("I2:I695").SpecialCells(xlCellTypeVisible)
End If
end_here:
Set wsLinesMaster = Nothing
Set wsFacility = Nothing
Set wbUpdate = Nothing
Set wbMaster = Nothing
Application.ScreenUpdating = True
Exit Sub
Item_Open:
sValue = Application.InputBox("Enter the TO: Bus Number here, Thank you.")
wsLinesMaster.Range("H6").Value = sValue
Debug.Print sValue
Return
End With
End Sub