Executing Macros Automatically

gbwcf

New Member
Joined
Oct 16, 2002
Messages
6
I have a list box in my workbook. Is there a way to have a macro run automatically when a selection is made in the list box?

Thank you.
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.

Chas17

Well-known Member
Joined
Oct 16, 2002
Messages
657
Private Sub ListBox1_Click()
Range("a1") = ListBox1.Value
End Sub
 

Chas17

Well-known Member
Joined
Oct 16, 2002
Messages
657
Private Sub ListBox1_Click()
Variable = ListBox1.Value
call yourmacro
End Sub
 

B_2

Board Regular
Joined
Aug 24, 2002
Messages
210

ADVERTISEMENT

Chas 17 how would i make the following macro run automatically?


Sub B_2()


If [A1].Value = "1" Then
MsgBox "Incomplete Invoice, please complete the following before saving." + vbCrLf + "" + vbCrLf + " Customer Reference, Invoice Number & Price.", VBINFO, " B_2 "
End If


End Sub
 

kskinne

Well-known Member
Joined
Feb 17, 2002
Messages
1,267
Office Version
  1. 365
Platform
  1. Windows
hey mate, just searching to see if you had posted anything lately - you could set this up so that an event triggers your macro, such as a change event or a calculation event. question: is the contents of A1 a formula, or is a value that has to be manually entered? this will affect what kind of event you would use to trigger your macro. let me know

kevin
 

B_2

Board Regular
Joined
Aug 24, 2002
Messages
210

ADVERTISEMENT

Hi bud

its a manual entry its a stripped down version
 

kskinne

Well-known Member
Joined
Feb 17, 2002
Messages
1,267
Office Version
  1. 365
Platform
  1. Windows
just insert this into your sheet module where this entry takes place by right clicking on the sheet tab and selecting 'view code':

Code:
Private Sub Worksheet_Change(ByVal Target as Range)
If Target.Address <> "$A" Then Exit Sub
If [A1].Value = "1" Then 
MsgBox "Incomplete Invoice, please complete the following before saving." + vbCrLf + "" + vbCrLf + " Customer Reference, Invoice Number & Price.", VBINFO, " B_2 " 
End If 
End Sub

take care
kevin
 

Chas17

Well-known Member
Joined
Oct 16, 2002
Messages
657
I tried kskinne code but did not work, did I misunderstand? Opps, code will work, missing a 1 for cell A1...
Manually input a 1 in cell a1 to cause auto display of msg?
I have Excel 97 at work, chas17
this also works
chas17:
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Set vrange = Range("a1")

For Each cell In Target
If Union(cell, vrange).Address = vrange.Address Then
If [A1].Value = "1" Then
MsgBox "Incomplete Invoice, please complete the following before saving." + vbCrLf + "" + vbCrLf + " Customer Reference, Invoice Number & Price.", VBINFO, " B_2 "
End If
End If
Next cell

End Sub
This message was edited by Chas17 on 2002-10-24 16:12
 

Forum statistics

Threads
1,143,709
Messages
5,720,391
Members
422,283
Latest member
Parvathy

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
Top