So having had one question answered, I now run into another problem. I have this code-
...that thanks to GWteB now works perfectly.
However, I have since run into another problem that I'm sure is very easy to solve for a non dunce like me.
That bit of code deletes the row that the data was in. In another sheet I have the following formulas:
Which basically looks up the 1st and last empty cells in the specified ranges and pulls it into a list for use elsewhere. When I delete the row using that function above, I encounter the #REF error because the row no longer exists- I would have thought if I was deleting Row 5 for instance, that row 6 becomes row 5, 7 becomes 6 and so on, and therefore the code would still function properly. Is there a way to resolve this by changing the formula?
VBA Code:
Private Sub CCOk_Click()
Dim Answer As Integer
Dim NewSht As Worksheet
Dim NewRow As Long
Dim ThisRow As Long
Answer = MsgBox("You have selected to cancel " & UCase(ActiveCell.Value) & vbNewLine & vbNewLine & "This will move the CHIS to Cancelled and remove ALL data from this page", vbExclamation + vbYesNo + vbDefaultButton2, "Are you sure?")
If Answer = vbYes Then
Set NewSht = Sheets("Cancelled")
Application.EnableEvents = False
Application.Calculation = xlCalculationManual
ThisRow = ActiveCell.Row
NewRow = NewSht.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
NewSht.Cells(NewRow, "A").Value = Cells(ThisRow, "A").Value
NewSht.Cells(NewRow, "B").Value = Cells(ThisRow, "B").Value
NewSht.Cells(NewRow, "C").Value = Cells(ThisRow, "C").Value
NewSht.Cells(NewRow, "D").Value = Cells(ThisRow, "D").Value
NewSht.Cells(NewRow, "E").Value = Cells(ThisRow, "E").Value
ActiveCell.EntireRow.Delete
Application.CutCopyMode = False
Application.EnableEvents = True
Application.Calculation = xlCalculationAutomatic
Else
'do nothing
End If
frmCancelCHIS.Hide
End Sub
...that thanks to GWteB now works perfectly.
However, I have since run into another problem that I'm sure is very easy to solve for a non dunce like me.
That bit of code deletes the row that the data was in. In another sheet I have the following formulas:
Excel Formula:
=IF(SHEET2!A4="","",(INDEX(SHEET2!A4:J4,MATCH(TRUE,INDEX((SHEET2!A4:J4<>0),0),0))))
Excel Formula:
=IF(SHEET2!A4="","",(LOOKUP(2,1/(SHEET2!A4:I4<>""),SHEET2!A4:I4)))
Excel Formula:
=IF(SHEET2!A4="","",(LOOKUP(2,1/(SHEET2!A4:J4<>""),SHEET2!A4:J4)))
Which basically looks up the 1st and last empty cells in the specified ranges and pulls it into a list for use elsewhere. When I delete the row using that function above, I encounter the #REF error because the row no longer exists- I would have thought if I was deleting Row 5 for instance, that row 6 becomes row 5, 7 becomes 6 and so on, and therefore the code would still function properly. Is there a way to resolve this by changing the formula?