Error Message

rubinda

New Member
Joined
Jun 26, 2018
Messages
36
I have the following code below, but I am not having any luck applying code that will do the following: If the cell in column E states, “Complete” and there is no associated date in column F, I’d like an error message to pop up and not allow the data to be transferred/deleted. Can you please assist?

Sub LaPorte()
Dim xRg As Range
Dim xCell As Range
Dim I As Long
Dim J As Long
Dim K As Long
I = Worksheets("La Porte").UsedRange.Rows.Count
J = Worksheets("La Porte-Closed").UsedRange.Rows.<wbr>Count
If J = 1 Then
If Application.WorksheetFunction.<wbr>CountA(Worksheets("La Porte-Closed").UsedRange) = 0 Then J = 0
End If
Set xRg = Worksheets("La Porte").Range("E1:E" & I)
On Error Resume Next
Application.ScreenUpdating = False
For K = 1 To xRg.Count
If CStr(xRg(K).Value) = "Complete" Then
xRg(K).EntireRow.Copy Destination:=Worksheets("La Porte-Closed").Range("A" & J + 1)
xRg(K).EntireRow.Delete
If CStr(xRg(K).Value) = "Complete" Then
K = K - 1
End If
J = J + 1
End If
Next
Application.ScreenUpdating = True

ActiveWorkbook.Save

[TABLE="width: 0"]
<tbody>[TR]
[TD][TABLE="width: 0"]
<tbody>[TR]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD]
[/TD]
[/TR]
[TR]
[TD]

[/TD]
[/TR]
[TR]
[TD]

[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
[TR]
[TD]

[/TD]
[/TR]
</tbody>[/TABLE]

 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
How about
Code:
Sub LaPorte()
   Dim Mws As Worksheet
   Dim Cws As Worksheet
   Dim i As Long

   Set Mws = Worksheets("pcode")
   Set Cws = Worksheets("sheet1")
   
   For i = Mws.Range("E" & Rows.Count).End(xlUp).row To 1 Step -1
      If Range("E" & i).Value = "Complete" And IsDate(Range("F" & i).Value) Then
         Rows(i).Copy Cws.Range("A" & Rows.Count).End(xlUp).Offset(1)
         Rows(i).Delete
      End If
   Next i
End Sub
 
Upvote 0
Where would I enter the pop up message? It does not allow the macro to work if there is no date in column F, but I am trying to enter a pop up message to notify the user. Thank you for the help!
 
Upvote 0
How about
Code:
   For i = Mws.Range("E" & Rows.Count).End(xlUp).row To 1 Step -1
      If Range("E" & i).Value = "Complete" And IsDate(Range("F" & i).Value) Then
         Rows(i).Copy Cws.Range("A" & Rows.Count).End(xlUp).Offset(1)
         Rows(i).Delete
      Else
         MsgBox "There is no dat in cell F" & i
      End If
   Next i
 
Upvote 0
This is great! One more question...

All cells in Row 1 are headings. How do I get the macro to not look at row 1 (or F1 for a date if column E states "Complete")?
 
Last edited:
Upvote 0
Make this change
Code:
 For i = Mws.Range("E" & Rows.Count).End(xlUp).row To [COLOR=#ff0000]2[/COLOR] Step -1
 
Upvote 0

Forum statistics

Threads
1,224,828
Messages
6,181,217
Members
453,024
Latest member
Wingit77

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top