LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #12   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson
 
Posts: n/a
Default How do I execute a macro based on the value of a cell in Excel

I'm not Norman.

But with 3 cells, I'd put a button on the worksheet that the user could click
when they had updated all three cells.

Then you could have a macro assigned to that button that determined the macro to
run.

Option Explicit
Sub testme()

Dim myStr As String
Dim myRng As Range

With ActiveSheet
Set myRng = .Range("a1:A3")

If myRng.Cells.Count < Application.CountA(myRng) Then
MsgBox "Please fill in all the cells"
Exit Sub
End If

myStr = .Range("a1").Value & .Range("a2").Value & .Range("A3").Value

If Len(myStr) 3 Then
MsgBox "Check your entries!"
Exit Sub
End If

Select Case myStr
Case Is = "111": Call Macro111
Case Is = "112": Call Macro112
'keep typing--I'm bored
Case Is = "333": Call Macro333
Case Else:
MsgBox "Please fix your choices!"
Exit Sub
End Select
End With

End Sub

And wouldn't you have 27 different macros:
3 for the first choice * 3 for the second choice * 3 for the 3rd choice
????

jkt wrote:

Norman-

I'm looking for a similar code as the one given in this example, however, I
want to reference 3 cell locations (A1, B1, C1) and based on their input run
a specific macro. Each cell has 3 options (1, 2, 3) and therefore having 18
different macros to run based on the combinations.

Do you have any suggestions? Right now I'm using a button to launch the
specific macro.

Thanks for your help!

"Norman Jones" wrote:

Hi Ltat42a,

To avoid posible confusion

Change A1 to the cell of interest.


was intended to refer to both of the lines:

If Not Intersect(Target, Range("A1")) Is Nothing Then
Select Case Range("A1").Value '<<=== CHANGE


---
Regards,
Norman



"Norman Jones" wrote in message
...
Hi Ltat42a,

Oooppps. I should have explained better. I want to get rid of the
images I use to run the macros. When a user inserts an "A" into a
particular cell, it will run the "A" macro that I created, when someone
enters "B", it runs the "B" macro...etc...etc...


In that case, try:
'===============
Private Sub Worksheet_Change(ByVal Target As Range)

If Not Intersect(Target, Range("A1")) Is Nothing Then
Select Case Range("A1").Value '<<=== CHANGE
Case "A"
Macro1
Case "B"
Macro2
Case "C"
Macro3
End Select
End If

End Sub
'<<===============

This is worksheet event code and should be pasted into the worksheets's
code module (not a standard module and not the workbook's ThisWorkbook
module):

*******************************************
Right-click the worksheet's tab
Select 'View Code' from the menu and paste the code.
Alt-F11 to return to Excel.
*******************************************


Change A1 to the cell of interest.

---
Regards,
Norman





--

Dave Peterson
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I change fill color in excel based on data in the cell Jason Southco Excel Worksheet Functions 1 September 29th 05 04:56 PM
Cell color based upon cell value My View Excel Discussion (Misc queries) 11 July 6th 05 03:59 AM
Possible Lookup Table Karen Excel Worksheet Functions 5 June 8th 05 09:43 PM
enter a new value into a cell using macro in excel cath Excel Discussion (Misc queries) 2 April 12th 05 11:32 PM
Excel formulas based upon the color shading of a cell? DGBG Excel Worksheet Functions 1 April 12th 05 10:35 PM


All times are GMT +1. The time now is 03:09 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"