VBA - make form show up for USER change

cmhoz

Active Member
Joined
Aug 20, 2006
Messages
268
Hi All....

I tried to ask this yesterday, but I think I explained myself very badly.

I have a cell - we'll call it A1.

Sometimes a USER will change the value in this cell.
Sometimes a MACRO will change the value in this cell.

I need to allow BOTH to happen and I cannot use 2 different cells as my zillion IF statements have already caused this file to be very large.

When a USER changes the value in this cell, I need a userform to appear that requires the user to read a message and confirm the change they've made.

When a MACRO changes the value in this cell, I do NOT want the user to have to deal with the previously mentioned form.

Currently - I have a macro that says: if A1 changes, show the form.

This is fine.. but it means the user still has to deal with the form when the MACRO has changed A1.

What I would like to do is tell the macro that changes A1 to click 'confirm' on the form that appears.

Can I do this?
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Hi cmhoz,

Tricky one here as Excel is doing exactly what you've asked it to do.

One solution may be to have your macro firstly populate a currently unused cell (say B1) with a "Y" flag, finish running the rest of the code and then change the value in B1 back to a "N" flag. You'll then need to change your Worksheet_SelectionChange event (or however you're calling the code to run when the tab in question changes) to only open if the value in cell A1 changes and the value in B1 is equal to "N" (i.e. a user changed the value in A1 not the macro).

HTH

Robert
 
Upvote 0
I would use a global variable (FLAG).

In the module declarations:
Public MacroCall as Boolean


In The MACRO That Changes The Cell Value:

YourMacro()
.....
Whatever preprocessing code you run before changing the cell value
.....

'SET THE FLAG FIRST
MacroCall - True

'Then Change The Cell Value
Sheets("YourSheetName").Range("A1").Value = SomeNewValue

....
Whatever postprocessing code you run after changing the cell value
....
End Sub


In Your CellChangeDetection Macro():

If MacroCall then
'RESET FLAG FOR NEXT MACROCALL
MacroCall=False
Else 'It was a user change
UserForm.Show
End if

'Do Whatever You Normally Do
...
...
...
End Sub
 
Upvote 0
The 'yes / no' flag in another cell works perfectly... this will be stored away for future use... so simple and yet never ocurred to me!

thanks!
 
Upvote 0
Glad it helped and thanks for the feedback :)

robert phillips' solution looks pretty nifty too ;)
 
Upvote 0

Forum statistics

Threads
1,214,377
Messages
6,119,185
Members
448,872
Latest member
lcaw

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