0

I have setting up the environment of programming the VBA Editor.

And I have a button on sheets("1"), after I click this button, I want to add the following code to sheets("2"), which sheets("2") already have some code. The code I decided would stored into string format.

Case "ABC:
    ...
    ...
    ...
    ...
End With

I want to add the code into line 15 of the sheets("2") code, but I do know how to write the code. Someone suggest me to read this tutorial http://www.cpearson.com/Excel/vbe.aspx but I cannot understand.

Clarify My Situation:

I have a database about some customer in excel, and with some code such as "case customer_1 ..... case 2 .....", which used to perform a combo box. what I want is when I add new customer in the database, press a button, a new case is automatic done, is that possible?

Can anyone write it to mee?

Community
  • 1
  • 1
  • 1
    If your code has enough information to write the VBA code to extend the `Select Case` when a new Customer is added, then you have enough information not to need the Select Case at all... – Tim Williams May 21 '16 at 06:46

1 Answers1

1

Friend,

I don't believe you want your button to write code for you. Maybe this is a super advanced program that will write code depending on current state when the button is clicked but I'm assuming, based on your reading material, that you want the button to execute code for you.

In this case write some test code on sheet 2.

 Sub testthing()
 Msgbox "h3llo world!"
 End sub

Then on your sheet one button and assign testthing macro to it.

You linked a button to a macro!

Then, change the macro to perform the desired task. Test it in the project manager. When you are sure it works, change the name and assign it to your button.

This should help, but it may not. I had to do some guesswork from your question. If this doesn't answer your question please add details and we will help you

EoinS
  • 5,405
  • 1
  • 19
  • 32
  • Thanks for your help. I have a database about some customer in excel, and with some code such as "case customer_1 ..... case 2 .....", which used to perform a combo box. what I want is when I add new customer in the database, press a button, a new case is automatic done, is that possible? – Hui Man Chang May 21 '16 at 05:47
  • in that case what you definitely want to do is have a column with the value you want added to the combo box for each customer. you can then use the combobox.listfill function. [here is a link](http://stackoverflow.com/questions/4200712/dynamically-set-listfillrange-in-excel-combobox-using-vba) to another similar question – EoinS May 21 '16 at 05:56
  • No. A have a customer and test type list. Customer can use listfill, but test type have to according to the customer. So, I have to use "Case" in the code. When new customer added, the problem comes. – Hui Man Chang May 21 '16 at 06:02