Free Microsoft Excel 2013 Quick Reference

Vba click command button Results

Hi There !
Can anyone help..?

I Have a Sheet where i have created a user interface using VBA ControlBox.

In Form I have 5 Fields which are as follws :

1) Label = Label4 (Date)
2) Label = Label5 (Time)
3) ComboBox = Combobox2 (List of Employees)
4) Command Button = CommandButton2 (Ok)
5) Command Button = CommandButton3 (Clear)

I have return following Code :

Private Sub ComboBox2_Change()
Label4.Caption = Date
Label5.Caption = Time
End Sub

Now I Have a list of employees in combo box, as I select a name in the combo box,
Both Label4 and Label5 stores current date and time respectively.

Now i have a second sheet where i have a format as follows ;

.........Column A....ColumnB....ColumnC....ColumnD....ColumnE....ColumnG....ColumnG
..............................1..............2..............3..............4.............5.............6 ......till 31
(Column B to Column AE refers Days of Month)

Row 4....John
Row 5....Jack
Row 6....Jimmi......................................................13.02
Row 7....Dalis

For Example :

I select Jimmi in Combo Box, Label4 get data as 04-05-2008 and label5 get data as 13.02.26.

what I want as i click ok, The data from Label5 of sheet1 should transfer to sheet2 on cell E6 as 13.02, as Label4 contains day 4 and combobox cantain Jimmi

plz help..

Vikash dalmia

Thanx in advance

Hi All

I have a weird one for you.

We have a spreadsheet with a command button on that links to VBA code to email a worksheet to a specified address the problem is when you click the print button the command button moves from the right of the printable area to ethe left of the screen and then has to be moved or it would be on the prints??

This same sheet is used my all my team and only this one laptop has this problem, it never yused to do this but nothing has changed as far as we can tell.

Any ideas why this is happening??



Imagine if every Thursday your shoes exploded if you tied them the usual way. This happens to us all the time with computers and nobody thinks of complaining.
-Jeff Raskin-

I've just written a few lines of VBA code that apply to a command button to clean up a template that I use, i.e. deleting column contents, moving info around, etc. When I press F8 and go through the VBA editor line by line, the code does what I want it to do. However, when I go to click the command back in the excel spreadsheet, it does nothing at all. The code I've written is as follows and any help would be much appreciated!

Private Sub CommandButton_Click5()

response = MsgBox("Prepare inventory template ready for consolidation?", vbYesNo, "Confirm")
lineNo = 1

If (response = VbMsgBoxResult.vbYes) Then

Workbooks.Open fileName:="c:KPMGMoW KPMG Report Consolidated Report TEMPLATE.xlt"

Worksheets("Baseline Inventory - Summary").Activate
Worksheets("Baseline Inventory - Summary").Range("J2:K1000").ClearContents

Worksheets("Baseline Inventory - Summary").Range("M2:N1000").Copy _
Destination:=Worksheets("Baseline Inventory - Summary").Range("J2")

Worksheets("Baseline Inventory - Summary").Range("M2:N1000").ClearContents

Selection.AutoFilter Field:=11, Criteria1:="COMPLETE", Operator:=xlAnd

Worksheets("Baseline Inventory - Summary").Range("F2:H1000").ClearContents
Worksheets("Baseline Inventory - Summary").Range("P2:R1000").ClearContents

Worksheets("Baseline Inventory - Summary").AutoFilterMode = False

Worksheets("Baseline Inventory - Full").Activate

Selection.AutoFilter Field:=11, Criteria1:="COMPLETE", Operator:=xlAnd

Worksheets("Baseline Inventory - Full").Range("F2:I1000").ClearContents
Worksheets("Baseline Inventory - Full").Range("K2:L1000").ClearContents

Worksheets("Baseline Inventory - Full").AutoFilterMode = False


End If
End Sub

Hey guyz~

Does anyone know how to create a command button that would act exactly like a PRINT command in the File menu in Excel?

Like I just click the command button and *ZaP* the Print Box comes up..

I think in vb6 its like printer.print but i'm not sure.. anyone out there know??



When i click print in my excel VBA program, some of the command button/ list
box will at right sides will move to left sides. Can anyone help me in this

I have a new 200" landscape monitor that replaced my traditional 17". The
resolution automaticallyl resized on connection and looks fine.

However, when I click a command button, the font size shrinks. It stays at
that level until I click a different button and then return to the original
button, when it shrinks again. It will eventually become invisible to the
naked eye.

Internet research seems to indicate this is a bug. A standard Excel button
accessed from View>Toolbars>Forms (not a VBA command button accessed from
Control Toolbox) seems to maintain its font size, but I don't know how to
link the Excel button to my VBA code. It only accepts standard macros.

I would love to stick with the command buttons but will switch to the Excel
buttons if that works. Please advise of a solution.



I am trying to develop a very very simple calculator to calculate the amount
of shares of stock I can afford.

I have three text boxes and a command button...
The first text box is for entering the amount of money I have to spend.
The second box is for entering the price of a share of stock.
The third box is supposed to display the amount of shares I can afford.

Basically just need the third box to divide my (money on hand) / (share
price) , when I click a command button.

How would I program this in VBA? Any links or examples to learn how to do
this on my own? I know this is simple, but don't know VBA.

I have $1000 on hand and the stock is $46 a share. When I click calculate I
want to display in the third text box that I can purchase 21.74 shares.


It sounds like you have different buttons on the sheets.

There's a commandbutton on the control toolbox toolbar that has code associated
with its click event. This gets copied when the worksheet gets copied.

There's a button on the Forms toolbar that can have a macro assigned to it.
This code doesn't automatically get copied.

If you rightclick on a button and see "assign macro", it's a Forms toolbar
button. If you don't see that option, it's from the control toolbox toolbar.

(It sounds like the simplest approach for you would be to replace the forms
toolbar buttons with control toolbox toolbar buttons (and move/copy/adjust the

Terry wrote:
> Can anyone help? I have a xls file OfficeXP. I have
> command buttons on it with vba code behind the buttons.
> In one file that I have when I use the copy sheet function
> it copies the button and the code behind the button to a
> new sheet in the same file. In the other file when a
> sheet is copied the button is copied but it does not have
> any coding behind it. Why would these behave
> differently? I want the code copied with the sheet and
> button.
> Thanks for any help..


Dave Peterson

In Excel 2007, on the View tab, in the Window section, is a Switch Windows

I would like to replicate that feature via VBA. Ie, during a subprocedure
run, I would like it to display the open workbooks and allow the user to
click on one of the results to activate that workbook.

What is the VBA for the Excel 2007 "Switch Window" command button?

Thanks in advance.

Well, most of the coding for the new quote module user form has been
going well. I have however, hit a snag. In the code below there is a
section that is causing an error. The debugger is saying the varible is
not defined. However, where it is stopping is not exactly a varible. It
is the name of a command button placed on the sheet mentioned in the
same line. Other than having the code select the right sheet first
(already incorporated into the code) I don't know how else to tell VBA
that it is a command button on the sheet and not one on the UserForm.

Any help will be appreciated.

The offending code is as follows:

'Saves the New Quote in the template and disables the command button
ActiveWorkbook.SaveAs ThisWorkbook.Name
ActiveWorkbook.Sheets("Start Here").Activate
cmdStartWizard.Enabled = False
cmdStartWizard.Caption = "Quote Wizard Disabled," & Chr(13) & " please use editing button."

And this is it in context of the entire click event:

Private Sub Image4_Click()
'Selects the quote sheet and activates
ActiveWorkbook.Sheets("Final Quote").Activate
'Changes the Quote Number to Increase by 1
Range("J4").Value = Range("J4").Value + 1
Range("J4").PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Application.CutCopyMode = False
'Inserts the Deliverable Types into Cell J5

'Inserts the TAT and type into Cell M4, and N4 respectivly
Sheets("Final Quote").Range("M4").Value = txtTAT.Text
Sheets("Final Quote").Range("N4").Value = lbxTAType.Text
'Inserts the Project Reference into Cell J7
Sheets("Final Quote").Range("J7").Value = txtProjectReference
'Inserts the Company Name into Cell C12
Sheets("Final Quote").Range("C12").Value = cmbClientList
'Saves the file with a unique name
'Declares Variables of the file name for saved as function
Dim QNum As String
Dim CNam As String
Dim CrDt As String
Dim VNum As String
'Defines the variable names from Quote Form
CNam = Range("C12").Text
CrDt = Format(Now, "mmddyy")
VNum = Range("K4").Text
'Saves the New Quote in the template and disables the command button
ActiveWorkbook.SaveAs ThisWorkbook.Name
ActiveWorkbook.Sheets("Start Here").Activate
cmdStartWizard.Enabled = False
cmdStartWizard.Caption = "Quote Wizard Disabled," & Chr(13) & " please use editing button."
'Defines the QNum varible to the new quote number after the template is saved to insure they_
'are saved with the same number
ActiveWorkbook.Sheets("Final Quote").Activate
QNum = Range("J4").Text
'Saves the New Quote as a unique file
ActiveWorkbook.SaveAs _
"X:_FEE SCHEDULE & QUOTE MODULECreated Quotes" & QNum & VNum & "-" & CNam _
& "-" & CrDt
'Disables step 1 and Shows step 2
End Sub


Here's to hope,

Amber_D_Laws's Profile:
View this thread:


All I need is to know how to use a command button in vba to store a
value in a cell in Excel.

I have a user form with two command buttons on it. one button is
labeled, "Test1", the other labeled, "Test2."

When the user clicks on the button labeled, "Test1", I want the word,
"Test1" to appear in the next available cell in row, "A." When the
user clicks onk, "Test2", I want the word, "Test2" to appear in the
next available cell in row, "A."

I want it set up so that every time the user clicks on either button,
it stores the value in the next available row without replacing the
exiisting value that is in the cell. So say the user clicks on the,
"Test1CommandButton", it stores, "Test1" in, "A1." And the next time
they click the, "Test1(or Test2)CommandButton", it stores, "Test1"(or,
"Test2"), in, "A2", ect..........Thats it.

I'm guessing the code is something like the following.......

Test1CommandButton Click()
Sheet("Sheet1").Range("A" & NextRow) = ("Test1").......???

I have a vba command button and checkbox on an excel spreadsheet.
How can I reference the chkbox from the click event of the command
button. I would like to turn it on and off from the click event of the
command button.

Both are from the vba toolbox and both are directly on the
spreadsheet and not on a vb form.

I don't know if this is possible but if it is it would be very helpful
to me



I would like to have a Command Button which when clicked "stamps" the current date in a specified cell

I anyone can assist.....

Hello Everyone.

I am having some troubles with creating code for my command button 1. I know how to create the code by double clicking, But the problem is when I double click it wants to put the code in that worksheet. I'm running a macro that runs on many different workbooks and sheets.

I guess I am asking how to put this code for the command button in my personnel projects so when I run my macro it will work with whatever workbook I am in.

Any Idea's Thank You, Mike


I have created a userform that allows users to enter data into a database spreadsheet. When I run a macro called showUserForm from the macro menu or from inside VBA the userform opens and runs properly.

End Sub
However, I would like users to be able to open the userform from excel with the click of a button, without having to goto the macro menu, or press a combination of keys. When I add a command button to the worksheet I get a RTE 13 'type mismatch' when trying to open the user form. I have tried changing the name of the command buttons in the sheet and in the user form so they don't conflict but am having no luck. Any ideas?

Here is the code for the button in the worksheet:
Private Sub CommandButton10_Click()
UserForm1.Show ' Have also used showUserForm here as well
End Sub
and from the userform:
Private Sub userform_initialize()

Sheets("Raw Data").Select
' Select Test Type
For i = 2 To 8
    UserForm1.ComboBox1.AddItem (Sheets("User Form Data").Cells([i], [1]).Text)
Next i
' Select Sample Type
For i = 2 To 7
    UserForm1.ComboBox2.AddItem (Sheets("User Form Data").Cells([i], [2]).Text)
Next i
' Select Pond Number
For i = 2 To 6
    UserForm1.ComboBox3.AddItem (Sheets("User Form Data").Cells([i], [3]).Text)
Next i

' Count the number of entries in the sheet
Cells([2], [2]).Select
Range(Selection, Selection.End(xlDown)).Select
rowe = Selection.Rows.Count
UserForm1.ScrollBar1.Max = rowe + 1
End Sub

Hello, I am completely new to VBA, so this is confounding me.
I have a form to add rows of data to a spreadsheet. I would like to change
a Command Button Caption and action based on data entry.
Example: user inputs width, length, and height. Command Button caption
reads "Calculate Volume". When the command button is clicked, the volume is
calculated and displayed on the form, the same command button caption then
reads "Enter Data." When the button is clicked again, the row will be added
to the spreadsheet and the form is ready to accept the next set of data.
Any help appreciated.

hello there,

i need you help becuase i am kind of stuck for now.

i am designing a macro in excel using VBA and i have put in a few codes for now.

i just want to know how is it possible to "code" the command button so that when clicked on, the windows explorer(just like when you have to open a file in microsoft word) will appear so that the user can select the file to be opened and once the user selects the file and clicks open, the result will appear in the textbox next to the button. but i dont want the file to be opened. i just want the result(path) of the file to appear in the textbox.

this is because i have another button at the bottom of the macro that would run all the selected files at the end because there is actually 3 command buttons and 3 textboxes that i need to "collaborate" at the end.

My Excel file has two sheets. The first sheet (we will call this sheet1) has one command button, and the second sheet (we will call this sheet2) has two command buttons. If the command button on sheet1 is clicked, it will copy the entire sheet2 to a new sheet (sheet3). Now, since the sheet has been copied to a new sheet, the command buttons in sheet3 lose their code. For example, here is the new code for one of the command buttons in sheet3:

Private Sub CommandButton2_Click()

End Sub

Now what I would like to do is insert some code into this new command button in sheet3 via the command button code from sheet1 that I originally used to copy sheet2 to sheet3. The code I would like to insert is as follows:

Application.DisplayAlerts = False
Sheets("sheet1").Visible = True
Application.DisplayAlerts = True

My problem is I do not know how to do this in VBA. Can someone help me out? Thanks!

sorry if these questions have been asked many times.

i am working through various books on using vba within excel and in each of the books i cant find any answers. Each of the books suggests that you create a command button so that if you click on it it will run your code. Is it possible to:

1. run the code by just pressing enter on your keyboard-ie if the value in cell(1,1) is a certain thing ,just by pressing enter can it trigger off the rest of the code instead of having to click on the command button
2. is it possible to have the command button on the top tool bar and if so how can i do this.

many thanks in advance

I've added a macro that runs vba code to perform some calculations. I wish
the user to click on a button in a cell on the worksheet to run this macro. I
am having trouble adding a command button to a cell? I have the control
toolbox up, but when i try to click on the command button or drag it to the
cell, nothing happens.
What to do?

No luck finding an answer? You could always try Google.