In Excel (via VBA) I preselect a range and set certain predefined sorting options. Instead of executing the sorting via VBA I want to display the dialog box as it would be when clicking on the sorting button in the ribbon.
This way the user would have the option to check the sorting settings and change them if necessary.
Here's a screen shot of what I mean. I marked the button and the dialog box with a red circle. Ignore the enabled filter, it should work if the filter is disabled as well:
Application.CommandBars.ExecuteMso "SortCustomExcel"
Related
Some built in excel formulas and functions require you to select a range and they give you a gui control to do so.
How can incorporate one of these Range GUI controls into a VBA form to allow the user to select a range?
An example of this Select Range GUI control can be found on the Create New Formula Rule (for Conditional Formatting) below.
This is called a RefEdit control.
You may need to enable this by right-clicking the Controls Toolbox and selecting the option for "Additional Controls". Scroll down and check the box for RefEdit.Ctrl. This will add the icon to the Controls Toolbox (it is third from the right, in the second row in my screenshot).
You may also need to enable this from the References in the VBE:
These controls return an address string based on the range selected by the user.
NOTE This control does not seem to play well if the user form is shown vbModeless. If you don't know what that means, then you don't need to worry about it. A form's default behavior is to .Show vbModal, and it should work in that context. See also HERE for other potential pitfalls when using a RefEdit control.
I have used VBA code to hide some rows. These rows are hidden when I click a check box.
The problem I have now is - the check boxes associated with each row will not hide. This also interferes with my original VBA code to hide the rows and stops working. I would like to hide these check boxes with the rows.
Please can you advise?
You need to set the checkboxes to "Move and Size With Cells." The last time I did this, with Excel 2003 it was easy: just right-click, choose "Properties" and choose that option. Now if you try that you'll see the option, but it's disabled:
So instead you need to access the more modern-looking format menu in Excel 2007 onwards. I did it by clicking the little "more" arrow on the Drawing Tools tab's Format group. For some reason it's enabled there. Once you set it your checkbox will hide with its row:
Is it possible to have a macro that, when pressed, pops up a message box asking for a string of text, and then a drop down that has a list of categories?
All I would need it to do is take this information and save it into a cell. If so, how?
[I'm going based on Excel 2007 here, but if you're using 2003, you'll have to navigate the menu structure]
Go to the VBE (by going to the View tab, then click on Macro - creating or editing an existing one will take you there - or click Alt+F11).
Go to the Insert menu, and select Userform. Drag a textbox (the ab|icon), and a combobox onto your form. To set the textbox value to a cell when you change the combobox, create a subroutine in the code to do this by double clicking on the combobox.
Set the combobox items by using the .additem method of comboBox1 in your code. These can be delineated or grabbed from a range in your code (see here)
Within that subroutine, set the value of whatever cell you want to textbox1.Text, which is the contents of the textbox.
I wanted to know after I initialize a combobox, is there a possibility that I can still stay active with the background Excel sheet using the cursor like scroll the sheet up/down, type words on the sheet, etc?
(While at the same time the combobox still stays on top of the Excel sheet doing whatever event you might want to do with your VBA?)
Go to the VBA IDE and select your form. In the properties list (on the left hand side of the screen), find the ShowModal property. Set this to False.
This will prevent the dialog from taking over the window.
Could someone please explain to me the difference between the combo box that's available via the Developer Ribbon in Excel 2007 vs. the Combo Box control that's in the VBA editor? I cannot get this simple line of code to work using the Developer combo box:
MsgBox Combo1.Value
I've tied it to the change event and it seems to be syntactically correct (I'm not a VBA coder by any stretch).
Is the Developer Ribbon version some bastardized craptastic Microsoft shortcut?
What I'm trying to do is populate a second combo box based on the selection of the first combo box. I'd rather not build a case statement for every possible selection. Is this possible using the Developer ribbon version?
You are talking about the Insert button on the Developer tab correct? From that button you can add an ActiveX control or Form control. You're better off using the form controls if your new to programming as they will behave more in line with any Excel VBA reading you've done and the help file. With the Form controls you can right click and choose 'View Code' and/or 'Rename Control and Code'. Renaming the control allows you to address it in VBA however you like. e.g. - Combo1.value or myFavoriteCombo.value
That being said, to answer your question directly, be sure you know the controls full name. If you used a form control and it was the first one you put on the sheet it will be named ComboBox1. To get to the combobox's properties you have to walk through it's 'parent' sheet.
i.e.
MsgBox Sheet1.ComboBox1.value (using the sheet's code name)
or
MsgBox Worksheets("SheetName").ComboBox1.value (using the sheets name as it appears on the Excel tab)