What’s wrong with my code?
Each cName is found on each sheet and the Delete procedure is performed. (as witnessed during debugging)
However, only Sheets(“Net”) and (“ADJ”) Ranges actually get deleted.
Identical code for any sheet between (“Net”) and (“ADJ”) the Range remains.
During debugging, if I manually select the sheets before each procedure is performed, the Range gets deleted. Adding Sheet.Select to the procedure solves the problem…But, why do the first and last procedures work without Sheet.Select?
Truly puzzled!
Each cName is found on each sheet and the Delete procedure is performed. (as witnessed during debugging)
However, only Sheets(“Net”) and (“ADJ”) Ranges actually get deleted.
Identical code for any sheet between (“Net”) and (“ADJ”) the Range remains.
During debugging, if I manually select the sheets before each procedure is performed, the Range gets deleted. Adding Sheet.Select to the procedure solves the problem…But, why do the first and last procedures work without Sheet.Select?
Truly puzzled!
Code:
Set ws = Worksheets("Net")
With Sheets("Net")
Sheets("Net").Unprotect
For i = 3 To 100
cName = Sheets("Settings").[C130].Value
If Range("A" & i).Value = cName Then
ThisWorkbook.Worksheets("Net”).Range("A" & i).Resize(1, 27).Delete Shift:=xlUp
End If
Next i
End With
Set ws = Worksheets("G1")
With Sheets("G1")
Sheets("G1").Unprotect
For i = 3 To 100
cName = Sheets("Settings").[C130].Value
If Range("A" & i).Value = cName Then
ThisWorkbook.Worksheets("G1").Range("A" & i).Resize(1, 26).Delete Shift:=xlUp
End If
Next i
End With
Set ws = Worksheets("G2")
With Sheets("G2")
Sheets("G2").Unprotect
For i = 3 To 100
cName = Sheets("Settings").[C130].Value
If Range("A" & i).Value = cName Then
ThisWorkbook.Worksheets("G2").Range("A" & i).Resize(1, 26).Delete Shift:=xlUp
End If
Next i
End With
''''''''''''''
'eight more sheets with identical code are not shown because.redundant
''''''''''''''
Set ws = Worksheets("ADJ")
With Sheets("ADJ")
Sheets("ADJ").Unprotect
For i = 3 To 100
cName = UFPS.ComboBox1.Value
If Range("A" & i).Value = cName Then
ThisWorkbook.Worksheets("ADJ").Range("A" & i).Resize(1, 24).Delete Shift:=xlUp
End If
Next i
End With