I was wondering if I could get some help with the following macro code. The current code (shown below) asks the question "Do you want to delete any quantities from the TY(F) column?. They are then asked to confirm the value. If they click continue the macro runs and the appropriate rows are deleted. My question is this. Can I add an additional question that asks " Would you like to delete any quantities in column LY(E)?" Next, if a confirmation message could display showing the values the user entered with a "Continue" button and a "cancel" button.
So if the user enters 3 in the first question and 6 in the second question the rows with 3 or less in column F and 6 or less in column E would be deleted. Now if column F had a 4 in it and column E had a 4 the row would stay as it did not meet the criteria of both questions.
Thanks for the help
Brian
If MsgBox("Do you want to delete any quantities from the TY(F) column?", vbYesNo, "Delete rows?") = vbYes Then
'ask user for value
Qty = Application.InputBox("What quantities for this year(F) would you like to delete?" & vbCrLf & _
"", Type:=1)
'if cancel is clicked, ignore the next part
If Not Qty = False Then
'display confirmation msgbox
If MsgBox("All totals with a quantity of " & Qty & " or less " & _
"will be deleted." & String(2, vbCrLf) & "Do you want to continue?", _
vbYesNo + vbExclamation) = vbYes Then
Application.ScreenUpdating = False
'loop through the rows--starting from the last row and going up the column
'deleting rows that have value <=Qty in column F
For i = LastRow To 2 Step -1
If Cells(i, 6).Value <= Qty Then Rows(i).Delete
Next i
End If
End If
End If
So if the user enters 3 in the first question and 6 in the second question the rows with 3 or less in column F and 6 or less in column E would be deleted. Now if column F had a 4 in it and column E had a 4 the row would stay as it did not meet the criteria of both questions.
Thanks for the help
Brian
If MsgBox("Do you want to delete any quantities from the TY(F) column?", vbYesNo, "Delete rows?") = vbYes Then
'ask user for value
Qty = Application.InputBox("What quantities for this year(F) would you like to delete?" & vbCrLf & _
"", Type:=1)
'if cancel is clicked, ignore the next part
If Not Qty = False Then
'display confirmation msgbox
If MsgBox("All totals with a quantity of " & Qty & " or less " & _
"will be deleted." & String(2, vbCrLf) & "Do you want to continue?", _
vbYesNo + vbExclamation) = vbYes Then
Application.ScreenUpdating = False
'loop through the rows--starting from the last row and going up the column
'deleting rows that have value <=Qty in column F
For i = LastRow To 2 Step -1
If Cells(i, 6).Value <= Qty Then Rows(i).Delete
Next i
End If
End If
End If