Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 23
Default Run a macro based on a cell value

I have a worksheet named "Sub-Form". On this worksheet, in cell "P10", I
have added a data validation list. When "Standard System" is selected from
the list in cell P10, I want to run a macro titled "SubForm1" that hides or
unhides rows on the worksheet. When "Display System" is selected from the
list in cell P10, I want to run a macro titled "SubForm2" that hides or
unhides a different set of rows. I know how to code the hiding and unhiding
of rows. What I need to know is how to get the value that is selected in
cell P10 (Standard System, Display System) to trigger the appropriate macro
to run. Another option is to have only one macro that is triggered by a
non-blank value in cell P10 that has IF/THEN statements based on what value
is in the cell ("Standard System", "Display System"), but I don't know how to
trigger the macro or write the IF/THEN statements.
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22,906
Default Run a macro based on a cell value

Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Me.Range("P10")) Is Nothing Then Exit Sub
Select Case Target.Value
Case "Display System"
SubForm1
Case "Standard System"
SubForm2
End Select
End Sub

This is sheet event code. Right-click on the sheet tab and "View Code"

Copy/paste into that module. Alt + q to return to the Excel Window.


Gord Dibben MS Excel MVP

On Sun, 30 Mar 2008 14:55:00 -0700, Lisa C.
wrote:

I have a worksheet named "Sub-Form". On this worksheet, in cell "P10", I
have added a data validation list. When "Standard System" is selected from
the list in cell P10, I want to run a macro titled "SubForm1" that hides or
unhides rows on the worksheet. When "Display System" is selected from the
list in cell P10, I want to run a macro titled "SubForm2" that hides or
unhides a different set of rows. I know how to code the hiding and unhiding
of rows. What I need to know is how to get the value that is selected in
cell P10 (Standard System, Display System) to trigger the appropriate macro
to run. Another option is to have only one macro that is triggered by a
non-blank value in cell P10 that has IF/THEN statements based on what value
is in the cell ("Standard System", "Display System"), but I don't know how to
trigger the macro or write the IF/THEN statements.


Reply
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
macro to go to cell based upon a calculation MARK M Excel Discussion (Misc queries) 7 November 30th 08 01:28 AM
Is there a way to disable a macro based on the value of a cell? Jeff Excel Discussion (Misc queries) 1 March 7th 08 06:43 PM
macro with input msg based on cell contents Janelle S[_2_] Excel Discussion (Misc queries) 2 February 9th 08 11:47 PM
Compiling macro based on cell values simonsmith Excel Discussion (Misc queries) 1 May 16th 06 08:31 PM
Formula or Macro to hide a row based on a cell value JP Excel Discussion (Misc queries) 0 February 3rd 06 06:10 PM


All times are GMT +1. The time now is 07:18 AM.

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

About Us

"It's about Microsoft Excel"