if cell is greater than "" then run macro

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm trying to create a macro that will open a Userform. The requirement
would be, is if the end user enters any data in Cell L12 then the form would
open up, if that cell is blank then nothing would happen. The Data Value
would be Numerical or Text. I know this is a worksheet_change but not quite
sure what the proper coding is. Any help is appreciated.
 
You'll need to use an event macro. Put this in the worksheet code module
(assuming a userform class named MyForm):

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim frmUser As MyForm
With Target
If .Address(False, False) = "L12" Then
If Not IsEmpty(.Value) Then
Set frmUser = New MyForm
frmUser.Show
End If
End If
End With
End Sub
 
Private Sub Worksheet_Change(ByVal Target As Range)

On Error GoTo ws_exit:
Application.EnableEvents = False
If Target.Address = "$L$12" And Target.Value <> "" Then
UserForm1.Show
End If

ws_exit:
Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.


--

HTH

RP
(remove nothere from the email address if mailing direct)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top