LauraC1984
Board Regular
- Joined
- Jan 30, 2020
- Messages
- 63
- Office Version
- 365
- Platform
- Windows
Hi,
I am currently working on a macro that will take the value from cell B12 on sheet name 'Input', It searches many sheets and when the value is found it deletes the row. I have the following macro but it keeps debugging at different points. and I don't understand the errors
can anyone help?
Sub updateJobdelete()
Dim fn As Range, i As Long, sh As Worksheet, adr As String, cnt As Long
Set sh = Sheets("Input")
chg = True
Dim ssh As Worksheet
For Each ssh In ThisWorkbook.Sheets
If ssh.Name <> "Input" And ssh.Name <> "Calendar" And _
ssh.Name <> "List" And ssh.Name <> "2020" Then
ssh.Visible = True
Set fn = ssh.Range("C:C").Find(sh.Range("B12").Value, , xlValues, xlWhole)
If Not fn Is Nothing Then
adr = fn.Address
Do
For i = ("B12") To 1 Step -1
If Range("C" & i).Value = Target.Value Then
Rows(i).delete
ct = ct + 1
End If
If fn Is Nothing Then
cnt = cnt + 1
End If
ssh.Visible = False
Next sheets("Calendar").Select
ActiveWorkbook.Save
If cnt = i - 2 Then
MsgBox "Job Number for job delete not found", vbExclamation, "OOPS"
Else
MsgBox "Change processed successfully", vbInformation, "DONE"
End If
End Sub
I am currently working on a macro that will take the value from cell B12 on sheet name 'Input', It searches many sheets and when the value is found it deletes the row. I have the following macro but it keeps debugging at different points. and I don't understand the errors
can anyone help?
Sub updateJobdelete()
Dim fn As Range, i As Long, sh As Worksheet, adr As String, cnt As Long
Set sh = Sheets("Input")
chg = True
Dim ssh As Worksheet
For Each ssh In ThisWorkbook.Sheets
If ssh.Name <> "Input" And ssh.Name <> "Calendar" And _
ssh.Name <> "List" And ssh.Name <> "2020" Then
ssh.Visible = True
Set fn = ssh.Range("C:C").Find(sh.Range("B12").Value, , xlValues, xlWhole)
If Not fn Is Nothing Then
adr = fn.Address
Do
For i = ("B12") To 1 Step -1
If Range("C" & i).Value = Target.Value Then
Rows(i).delete
ct = ct + 1
End If
If fn Is Nothing Then
cnt = cnt + 1
End If
ssh.Visible = False
Next sheets("Calendar").Select
ActiveWorkbook.Save
If cnt = i - 2 Then
MsgBox "Job Number for job delete not found", vbExclamation, "OOPS"
Else
MsgBox "Change processed successfully", vbInformation, "DONE"
End If
End Sub