Computing.Net > Forums > Office Software > Excel macro

Excel macro

Reply to Message Icon

Original Message
Name: AlwaysWillingToLearn
Date: July 25, 2007 at 07:39:46 Pacific
Subject: Excel macro
OS: winxp pro
CPU/Ram: p4
Model/Manufacturer: msi
Comment:

hello,

i have created a drop down menu using validation form the data menu. i have created a list of items i want to populate my list with and have assigned the source to it. what i want to do it make a button which can swich from one datasource to another for this dropdown for example

if range A1 has the drop down

when i press button1 the dropdown has

a
b
c

when i press button2

the dropdown has

d
e
f

any ideas please?

Thanks,


Report Offensive Message For Removal


Response Number 1
Name: DerbyDad03
Date: July 25, 2007 at 09:49:12 Pacific
Reply: (edit)

If you record a macro while setting up your validation, you'll get something like the code below.

Make a copy of the recorded code, then change the names and the ranges they refer to. (See my '*** lines.)

Assign each macro to it's own button and click to your heart's content.

Sub Button1()
'*** You'll need another copy of this code called something like Sub Button2()
With Selection.Validation
'*** Change the above line to read With Range("A1").Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="=$K$1:$K$7"
'*** In the Button2 code change the last part to be Formula1:="=$L$1:$L$7"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
End Sub


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Excel macro

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




Have you ever used OpenOffice?

Yes, as my main suite.
Yes, occationally.
Yes, but only once.
No, never.


View Results

Poll Finishes In 5 Days.
Discuss in The Lounge