Nlhicks
Active Member
- Joined
- Jan 8, 2021
- Messages
- 264
- Office Version
- 365
- Platform
- Windows
This code works to find any value I need unless there are multiple lines with the same name and circuit number. At that point, it still filters but it filters all four lines. I need to add something to this that makes sure that only one line shows up on "Sheet2" and if not then use the fourth filter to make sure there is only one line.
Maybe like this If Worksheets("Sheet2").Range("A2:I685").SpecialCellsTypeVisible>1 Then
.AutoFilter field:=13, Criteria1:=Worksheets("Line Update").Range("H6")
End If
Does anyone have a suggestion? I need to not do any of my other code until I make sure there is only one line otherwise it messes us everything else.
Sub FindRightCell()
Dim LineUpdate As Worksheet
Set LineUpdate = Worksheets("Line Update")
With Worksheets("Sheet2").Range("A1")
If LineUpdate.Range("D5").Value <> "" Then .AutoFilter field:=10, Criteria1:="*" & Worksheets("Line Update").Range("D5") & "*"
If LineUpdate.Range("D6").Value <> "" Then .AutoFilter field:=11, Criteria1:="*" & Worksheets("Line Update").Range("D6") & "*"
If LineUpdate.Range("D7").Value <> "" Then .AutoFilter field:=12, Criteria1:=Worksheets("Line Update").Range("D7")
'If LineUpdate.Range("H6").Value <> "" Then .AutoFilter field:=13, Criteria1:=Worksheets("Line Update").Range("H6")
'End If
End With
Worksheets("Line Update").Range("C11").Value = Worksheets("Sheet2").Range("B2:B685").SpecialCells(xlCellTypeVisible)
Worksheets("Line Update").Range("C12").Value = Worksheets("Sheet2").Range("C2:C685").SpecialCells(xlCellTypeVisible)
Worksheets("Line Update").Range("C13").Value = Worksheets("Sheet2").Range("D2:D685").SpecialCells(xlCellTypeVisible)
Worksheets("Line Update").Range("C14").Value = Worksheets("Sheet2").Range("E2:E685").SpecialCells(xlCellTypeVisible)
Worksheets("Line Update").Range("C15").Value = Worksheets("Sheet2").Range("F2:F685").SpecialCells(xlCellTypeVisible)
Worksheets("Line Update").Range("C16").Value = Worksheets("Sheet2").Range("G2:G685").SpecialCells(xlCellTypeVisible)
Worksheets("Line Update").Range("C17").Value = Worksheets("Sheet2").Range("H2:H685").SpecialCells(xlCellTypeVisible)
Worksheets("Line Update").Range("C18").Value = Worksheets("Sheet2").Range("I2:I685").SpecialCells(xlCellTypeVisible)
Maybe like this If Worksheets("Sheet2").Range("A2:I685").SpecialCellsTypeVisible>1 Then
.AutoFilter field:=13, Criteria1:=Worksheets("Line Update").Range("H6")
End If
Does anyone have a suggestion? I need to not do any of my other code until I make sure there is only one line otherwise it messes us everything else.
Sub FindRightCell()
Dim LineUpdate As Worksheet
Set LineUpdate = Worksheets("Line Update")
With Worksheets("Sheet2").Range("A1")
If LineUpdate.Range("D5").Value <> "" Then .AutoFilter field:=10, Criteria1:="*" & Worksheets("Line Update").Range("D5") & "*"
If LineUpdate.Range("D6").Value <> "" Then .AutoFilter field:=11, Criteria1:="*" & Worksheets("Line Update").Range("D6") & "*"
If LineUpdate.Range("D7").Value <> "" Then .AutoFilter field:=12, Criteria1:=Worksheets("Line Update").Range("D7")
'If LineUpdate.Range("H6").Value <> "" Then .AutoFilter field:=13, Criteria1:=Worksheets("Line Update").Range("H6")
'End If
End With
Worksheets("Line Update").Range("C11").Value = Worksheets("Sheet2").Range("B2:B685").SpecialCells(xlCellTypeVisible)
Worksheets("Line Update").Range("C12").Value = Worksheets("Sheet2").Range("C2:C685").SpecialCells(xlCellTypeVisible)
Worksheets("Line Update").Range("C13").Value = Worksheets("Sheet2").Range("D2:D685").SpecialCells(xlCellTypeVisible)
Worksheets("Line Update").Range("C14").Value = Worksheets("Sheet2").Range("E2:E685").SpecialCells(xlCellTypeVisible)
Worksheets("Line Update").Range("C15").Value = Worksheets("Sheet2").Range("F2:F685").SpecialCells(xlCellTypeVisible)
Worksheets("Line Update").Range("C16").Value = Worksheets("Sheet2").Range("G2:G685").SpecialCells(xlCellTypeVisible)
Worksheets("Line Update").Range("C17").Value = Worksheets("Sheet2").Range("H2:H685").SpecialCells(xlCellTypeVisible)
Worksheets("Line Update").Range("C18").Value = Worksheets("Sheet2").Range("I2:I685").SpecialCells(xlCellTypeVisible)