Jump to content

running Macros based on what is selected in the listbox?

- - - - -

  • Please log in to reply
2 replies to this topic

#1
hattrick_123

hattrick_123

    Newbie

  • Members
  • Pip
  • 2 posts
Hi there

I have been looking at various options for solving this problem but cannot seem to find the solution. Appreciate any help. I am using Excel03.

I have a listbox with 3 items(1,2,&3) and if I select 1, 2, or 3 the selected value will appear in cell A1.

Now based on this I want to run macro 1 if 1 is selected (A1=1),
run macro 2 if 2 is selected (A1=2),
run macro 3 if 3 is selected (A1=3).

But I am having no joy and would appreciate any pointers/advice.

this is what I have so far


Sub CopyPaste1_2()


If a1 = 1 Then

CopyPaste1

ElseIf a1 = 2 Then

CopyPaste2

End If

'CopyPaste3

'DeletePaste

End Sub


Sub CopyPaste1()


    Range("D1").Select

    Selection.Copy

    Range("F1").Select

    ActiveSheet.Paste

End Sub

Sub CopyPaste2()


    Range("D2").Select

    Application.CutCopyMode = False

    Selection.Copy

    Range("F2").Select

    ActiveSheet.Paste

End Sub

Sub CopyPaste3()


    Range("D3").Select

    Application.CutCopyMode = False

    Selection.Copy

    Range("F3").Select

    ActiveSheet.Paste

End Sub

Sub DeletePaste()


    Columns("F:F").Select

    Application.CutCopyMode = False

    Selection.ClearContents

End Sub


#2
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,722 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
For that you're going to want to use an array of function pointers. I'll walk you through it if you have problems.
sudo rm -rf /

#3
hattrick_123

hattrick_123

    Newbie

  • Members
  • Pip
  • 2 posts
Many thanks for this, but that looks a bit complicated for my novice eyes.

Anyhow the attached(Call macro from ComboBox.zip) which I found here answers my question.

However that has lead me to another – what is the difference between a combo box from the forms toolbar and a combo box from the controls toolbar. I’m sure I’ll find out with time :)

Edited by hattrick_123, 11 May 2011 - 04:32 PM.
testing





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users