I am newbie in excel and I really need a button that if pressed adds a certain value to the cells I selected, is that possible?
You can add buttons to Excel by enabling developer mode:
On the File tab, go to Options > Customize Ribbon.
Under Customize the Ribbon and under Main Tabs, select the Developer check box.
Then on the developer ribbon you can click insert, then select a button to draw onto the sheet.
You will then be given the option to assign a macro to the button (Also later accessible by right clicking the button).
As for the VBA code of the macro, you would need to be more specific about what functionality you require, is the 'certain value' to be added to the selected cells always the same value?
Someone answered me in two minutes on another site with this perfect code for what I wanted, thanks a lot sir. It works like magic.
Sub Add_to_Selection()
If Not IsNumeric([E4]) Then
Exit Sub
Else
Dim cell As Range
For Each cell In Selection
cell.Value = cell.Value + [E4].Value
Next cell
End If
End Sub
Related
I have a very wide excel spreadsheet. It's formatted in such a way that there is specific data on each screen page. I have the first column frozen so I can place hyperlink buttons vertically. These buttons are hyperlinked to each of the formatted pages in the worksheet.
When I click one of the hyperlink buttons I would like the worksheet to scroll so the target cell in the UPPER LEFT corner of the screen.
I have googled and found this VBA code to place in the "thisworkbook" section of the VBA editor.
Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
ActiveWindow.ScrollRow = ActiveCell.Row
ActiveWindow.ScrollColumn = ActiveCell.Column
End Sub
This code does not seem to work for me. If I'm at the far left of the screen and press the hyperlink button it scrolls to the target cell until it gets on the active screen. So basically it always ends up somewhere on the Upper right of the screen. However, if I click the hyperlink buttons the require the page to scroll to the left side of the worksheet it does work.
How can I make it so the target cell is ALWAYS in the upper left of screen after I press the hyperlink button?
Also, how do I know the above code is even running? The hyperlinks seem to be doing the same thing with or without it. I just cut and pasted the code into the VBA editor (per google) for thisworkbook. Is that it or do I need to check something so it will be activated?
Thanks in adavance.
There's a way to do that without using VBA. You can just use a normal hyperlink in the spreadsheet, and link it to "Place in This Document". Make sure you pick the correct Sheet and Type the cell reference that you want to go to (I assume this is A1). This will make sure that whenever you click that particular link, it will always go to that particular spot.
Here's how the edit hyperlink would look in an empty spreadsheet.
I have three buttons in my Excel spreadsheet called Button_01, Button_02 and Button_03. Now, I want to select all of them and tried to go with the following VBA:
Sub Select_Objects()
Sheet1.Buttons("Button_01").Select
Sheet1.Buttons("Button_02").Select
Sheet1.Buttons("Button_03").Select
End Sub
This VBA only selects each of the buttons one after another so in the end only Button_03 is selected.
What do I need to change in this code so all three buttons remain selected. The same if I would select them manually with Ctrl?
Try this one:
Sheet1.Shapes.Range(Array("Button_01", "Button_02", "Button_03")).Select
Hope it helps
I need help with figuring out how to make a macro run when I click the ComboBox. For example, the ComboBox is pulling in a list from another column, if that column changes, I want to see the updated list when I click the ComboBox for this first time. Right now it is running the macro after I click the ComboBox and then click on an option that already exists. Once I reopen, then I see the updated list I want to see the first time a user clicks. Any help is appreciated, thank you so much!!!!
Sub costcenterdup()
'
' costcenterdup Macro
Application.ScreenUpdating = False
With Sheets("Dollars")
.Range("K9:K" & .Cells(9, "K").End(xlDown).Row).Copyy
Destination:=Sheets("LookUp").Range("E2")
End With
With Sheets("LookUp")
.Range("$E2:E" & .Cells(.Rows.Count, "E").End(xlUp).Row).RemoveDuplicates
Columns:=1, Header:=xlNo
End With
With Application.Worksheets("LookUp")
.Range("E2:E5000").Sort Key1:=.Range("E2")
End With
Range("C5").Select
Application.ScreenUpdating = True
End Sub
There are two types of combo boxes that you can add to a sheet.
One of them is a form combo box, which can be accessed from the "Forms" toolbar.
The other one is the ActiveX combo box, which can be accessed from the "Control Toolbox" toolbar.
A very good explanation of these is here (link is courtesy of #Ralph): http://peltiertech.com/forms-controls-and-activex-controls-in-excel/
To the first one you can only assign one macro when the combo box changes.
But to the ActiveX ComboBox you can assign several. If you add it to the GotFocus event then it will run the macro every time the box gets focus:
Private Sub ComboBox1_GotFocus()
'Add code here
End Sub
But if I correctly understand your question, that you want to have the combo box have the data in it from a column – then you need the first version of combo box (the form one) and simply right-click on it, select "Format control..." and on the Control tab set the cells you want the data filled with. It will automatically update the combo box for you and you will always see the values from the cells. There is no need for a macro in this case. See the below image:
I need to increment the value in a cell by the set value in some other cell, each time I click a macro button, or alternately clicking a check box.
I tried various formulas but they always return a circular error.
I looked at multiple replacement/increment macros but none do what I need or worked as described.
I'm good at formulas, but my VBA skills are very rudimentary at best.
Put an ActiveX button on the worksheet with Developer ► Insert ► ActiveX Controls ► Command button. Right click the button and choose View Code. Modify the code to the following:
Private Sub CommandButton1_Click()
[a1] = [a1] + [a2]
End Sub
Tap [Alt]+Q to return to your worksheet. Turn off Developer ► Design Mode. Every time you click the button, the value of A2 will be added to A1.
I have a workook in which userform will pop-up only if somesheets as present (say Sheeta). On clicking submit in userform will do and some calculation and store it in Sheetb. I need to lock some cells from editing in sheetb.
code used in submit click
Sheets("sheetb").unprotect password="test"
'code for calculation
sheets("sheetb").protect password="test" , AllowFormattingcells:=true 'This statement locks the unlocked cells
The above code works fine when pop-up the userform through button say (loadfile).
I don't know what mistake I made.
Please help me to get rid of this...
Note : I want to prevent cells Sheets("sheetb").Range("N10:Q20") only from editing. Is it possible to prevent cells from editing without protecting a sheet.
Thanks in advance!!!
Following my comment, if your goal is to protect only range "N10:Q20" on "sheetb" and leave the rest unprotected, then you can do that very easily: simply select the whole range on the worksheet (CTRL+A), press the right-mouse button and go to "Format the cells.."; select Protection tab and untick "Locked" box. Next, select your range "N10:Q20" and do the same procedure but this time tick the "Lock" box. Now, run your code and you will notice that only your selected range will be protected, all the other cells on "sheetb" will stay unlocked and editable.