Return a value to the previous value??

ShaunTur

New Member
Joined
Jun 13, 2011
Messages
3
I'v got a private sub for a worksheet change that looks up to see if values are blank which decides if the user can do a change or not.
Heres my code so far:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    If Target.Column <> 2 Then Exit Sub
    
    If WorksheetFunction.CountA(Sheets("Order Form").Range("C7", "I300")) = 0 Then
    Exit Sub
    Else
    MsgBox "Cant Change Products Through The Week"
    
    End If
End Sub
I want to insert a code after the msgbox that returns the value back to the value before the change?
or do i have to set up a worksheet_selectionchange macro too?
Really appreciate the help
Thanks
Shaun
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Try this:-
Code:
    With Application
      .EnableEvents = False
      .Undo
      .EnableEvents = True
    End With
 
Upvote 0
Or is there a way to set a variable for any selected cell

Worksheet_Selection ()
myvalue = activecell.value
end sub

then call that variable from the other sub
 
Upvote 0
a) I hope you are female

b) my invoice is in the mail

:laugh:
 
Upvote 0
On a serious note, if you're going to do this sort of thing, please test what happens under every possible circumstance. Check that the code behaves predictably when the user:-
  • selects a range of cells starting and/or ending in column B, wiping from left-to-right and/or right-to-left, and presses the Delete key to clear the entire range
  • selects one or more entire rows upwards and/or downwards or one or more entire columns left-to-right and/or right-to-left, and presses the Delete key to clear them
  • copies a value from elsewhere in the worksheet and pastes it into column B, or into multiple columns and/or rows
Finally a word about Application.EnableEvents. If you set it to False and your program stops or abends for any reason before it's reset to True, VBA will be left in a state where events are not enabled and macros will not run.

If you suspect this might be the case after an abend, open the Immediate window (Ctrl-G) and type ?application.enableevents followed by Enter. If it reports False, type application.enableevents=true followed by Enter to re-enable them.
 
Upvote 0

Forum statistics

Threads
1,224,618
Messages
6,179,919
Members
452,949
Latest member
beartooth91

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