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
Related
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
I have an Index/Match Code to Display a Description of an Item by changing the Label when a Value is Entered in a Texbox , usually the way i do it is put the code on the
Texbox_Change()
....Code here
End Sub
but now i have a lot of textboxes and i don't want to write this code one by one
so i tried to put my code on the 'UserForm_Initialize()' but this only runs only once. and i was wandering if there was a way i could create a SUB that Monitors Textbox Changes for all of the Textbox's in my user form.
I have made two active X combo boxes for a list of 220 sites. Before making the active x combo box i have made a sheet that searches through my data and finds the sites that match with what i am typing as i go.
I then used the name manage, refering to the formula in the first cell of the list
=Sheet1!$G$2:INDEX(Sheet1!$G$2:$G$220,COUNTIF(Sheet1!$G$2:$G$220,"?*"))
I have then writen this in the ListFillRange in the properties of my combo box.
It works fine for one, but once i had made the second one and selected the site the first one will no longer let me search through.
I have used the same formulas on both but they originate from different sheets to see if this fixed the problem however that was unsuccessful. (the boxes are on different sheets) When i click on the next sheet after using the box on the first sheet, it still shows part of it as if it is crashing.
The boxes are independent so I'm not sure what to do next as i need to add another 3 on separate sheets.
I am also using this code for each box
Private Sub ComboBox1_Change()
ComboBox1.ListFillRange = "MList"
Me.ComboBox1.DropDown
End Sub
and similar for the other button but with a different range.
There is no need to use VBA for this, the Change Events specifically, if you just want to use and fill the combo boxes with Named Ranges.
The scenario I think you try to do is:
Create Named Ranges that will be the source of your combobox:
Fill the range with your data, select the range, Right Click, Select Define Name and give the range a name. MList in your case I believe.
Create Combobox:
Goto Developer Tab, Insert in your case ActiveX ComboBox, Draw it on your sheet, right click the ComboBox, select properties, find ListFillRange in properties and enter the name of the Named Range you created in step one
Repeat for Combobox 2, with the same or a different Named Range depending on what you try to do
Leave Design Mode
Boths Comboboxes can now be used to type in what you are looking for.
If this is not what you tried to do, please try edit your question and in detail try to explain what you try to do and what you like to accomplish by doing so.
I have a Slicer in my excel with the following 2 values
Add Customer
Add Vendor
I want to open 2 different forms when click on those value. Can anyone please help me with this.
Yes, you can call different forms on slicer clicks, check the below code. Hope it suits your requirement and if not you can use to change as per your requirement.
On Writing your code in Worksheet_PivotTableUpdate event, on each slicer click this event will get called.
Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)
If ActiveWorkbook.SlicerCaches("Slicer_Region").SlicerItems("East").Selected = True Then
UserForm1.Show
ElseIf ActiveWorkbook.SlicerCaches("Slicer_Region").SlicerItems("West").Selected = True Then
UserForm2.Show
End If
End Sub
Where,
Slicer_Region = "Name to use in formulas"
You can get this name by right click on slicer and click slicer settings. and find the name to use in formula.
East or West = "Names of slicers"
For which you want to call different forms.
The solution works BUT THE CODE MUST BE in the code module of the worksheet with the pivot table
It does not work on main slicer, however if you select any particular item it works. In that case it is better to set the macro on the slicer itselft. You just need to click on slicer and it will be run automatically.
I'm very new to VBA and i searched and searched on Google, but can't find an example which deals with my problem.
I got a list of names which I want to put inside a selectable dropdownlist. When i click their name I want to run a different macro i made with their name on.
I tried a lot of things yesterday, but everytime it only succed me to assign 1 macro which was called no matter which name i pressed.
I think the solution is pretty simple, but i really got no clue how to do this the most simple way. So hopefully any of you got a link to a simple tutorial or can explain it to me in steps.
Thanks in advance
EDIT:
I got 2 names.
Birgitte = A:1
Thomas = A:2
I got a form comboxbox where both names are in.
When i press Birgitte i want a macro called BS_Opgave() to run and when i pres Thomas i want Macro TR_Opgave to run.
My problem is I'm not sure how to connect the combox selection to a Macro in the VBA editor. I'm acutyally confused about everything in the editor about comboxing.
Paste this code in a module. The Right Click on the Combobox and assign the macro DropDown1_Change to it :) And you are done.
Option Explicit
Sub DropDown1_Change()
With ThisWorkbook.Sheets("Sheet1").Shapes("Drop Down 1").ControlFormat
Select Case .List(.Value)
Case "Birgitte": BS_Opgave
Case "Thomas": TR_Opgave
End Select
End With
End Sub
Sub BS_Opgave()
MsgBox "You selected Birgitte"
End Sub
Sub TR_Opgave()
MsgBox "You selected Thomas"
End Sub
ASSUMPTIONS
I am assuming the following
The name of the combobox is "Drop Down 1"
The combobox is in "Sheet1"