Make Excel select cell when clicked if previously selected cell had validation dropdown list displayed - vba

If the user is on a cell in Excel, and that cell has a data validation dropdown list, and the user has the list displayed:
If the user then clicks on another cell, that other cell is not selected. Instead, all that happens is that the first cell's data validation dropdown list is dismissed. The first cell is still selected, until the user clicks on the second cell again.
Is there any way in VBA to detect when that happens, and select the second cell so the user doesn't have to click a second time?
I'm on Excel 2007.

You could get the behavior you want by using a ComboBox fit into the cell and use that instead of the built-in data validation. You just lock the cells and have a ComboBox appear in the cells in that column that they select. If they choose another cell the combobox simply goes invisible. This also solves the problem of using a custom font (if you have a font with special symbols, for example.)

Related

Excel VBA: Deselect a cell

Is there a way to deselect a cell with Excel VBA? My situation is I have a worksheet double-click event, so the cell must be selected for the macro to run. But that leaves a flashing cursor in the cell that's selected.
How do I deselect the cell once the macro is done? I've searched Google for a few methods and tried some, but none quite work properly. I've tried moving the selection left one cell and then right, back to the original cell. But for some reason, the cursor is still flashing in the selected cell. Any help?
The Worksheet_BeforeDoubleClick event has an argument called Cancel. Have a line in your double click event code that sets Cancel = True and that will cancel the cell edit mode and just have the cell selected instead of the blinking cursor within the cell

excel checkboxes to hide and unhide rows disappear when i save and reopen file

I have 2 sheets in excel where if you tick the checkboxes on the first sheet it hides or unhides the rows on sheet2. I used active x controls and set checkbox properties to 'move and size with cells' but when i unhide the rows, the checkboxes disappear but are still in the document as their height changes and remains at 0.(the rows appear just fine). Please help!!
ActiveX checkboxes are reknown for problems like these. FOrms checkboxes are a bit better, but I would advise to just use cells with data validation set to list and have it accept 0/1 or True/False. It is relatively easy to set up an event macro that toggles the value of those cells after a double-click for instance.

vba can't type a simple function in textbox controlsource property

I'm new to VBA btw ..
I built a userform with multiple textboxes that return a value based on a combo box selection.
so in the textbox control source property, I can write formulas like "=index( match) and stuff
but can't write something like "=sheet1!b4+sheet1!c7"
and I get "Couldn't set the controlsource property, invalid property value" error
my formulas are more complicated than this of course, (and they work if I type them in a normal cell) .. but it seems that I can't write any calculation sign + - * / into the controlsource property
any idea why ????
That's because the cell is then "connected" to the text box. If you update the text box you are also updating the linked cell on sheet1. But if you are trying to link two cells with =sheet1!b4+sheet1!c7 and afterwards you are changing the value in the textbox then Excel wouldn't know which cell to update. Should only Sheet1B4 get updated or only Sheet1C7? Maybe both cells get 50% of the value?
In short: one text box can have only one control source and thereby link the text box to the referenced cell.

Set focus on ComboBox (ActiveX Control) after code execution

I have an Excel file with a combobox (name = "Combobox1"). After running a script (basically pasting the selected value in "the next row" of a column) I want the focus to be reset on the combobox at the end of the script, so doing allowing me to type the next entry in the Combobox without having to click on the ComboBox text field first.
This does the job in Excel 2013 but I would like to have it working in 2007 as well:
Combobox1.Activate
Anyone any idea?
Or:
I can replace the combobox with an in-cell dropdown list (data validation) and the same data validation as the one I have in the combobox at the moment, but then I have another issue:
For a ComboBox you can choose to have the dropdown list active, but for an in-cell data validation that is not the case, at least not if you want to be able to type in the cell after the list is shown with ALT+UP or
Application.SendKeys "%{UP}"
Any idea here?
If this combobox is on a worksheet and not a userform, then "Combobox1.select" should return the focus to the combobox.

How do I link and excel slicer to an excel slider (scroll bar)?

Excel 2010 have a PivotTable feature called a slicer. Slicers are nice. However, when your slicing on a column with tons of unique values, slicers suck.
I want to know how to tie a slicer to a "slider" (scroll bar), that way I can link a Macro to the Scroll bar that selects all Slicer values less than or equal to the value on the scroll bar. When I change the scroll bar by clicking, the value changes and thus the selected values of the slicer change.
Found a way to do this and avoid the middle man (the slicer). This may have to do with how my own particular data is structured, but I think it will work in general.
Using the Macro Recorder, record yourself setting a value filter on the column you want to have a slicer on. In my case the column is % of Sales with Vendor
We use Value Filters -> Greater Than. Select the column, then input the value. Your pivot table will change. Stop the Macro Recorder.
We need another piece of code. Record a new Macro. With this Macro, clear the filter you just set on the pivot table, then stop the Recorder.
Developer -> Insert -> Scroll Bar. Just put the scroll bar anywhere for now.
Enter a value in the range of values of % of Sales with Vendor into a cell like A1. While my pivot table shows the data as a percentage, the underlying source uses decimals. For 20%, I will enter 2. Why? You CANNOT scroll bar on non-integer values. I really want 0.2 but by entering =A1/10 in an adjacent cell, I can always reference the value I really want
You need to create one macro only (from the two you recorded) that looks like this.
Sub sliderfilter()
'
' sliderfilter Macro
'
'
ActiveSheet.PivotTables("PivotTable2").PivotFields("Vendor"). _
ClearAllFilters
ActiveSheet.PivotTables("PivotTable2").PivotFields("Vendor").PivotFilters. _
Add Type:=xlValueIsGreaterThan, DataField:=ActiveSheet.PivotTables( _
"PivotTable2").PivotFields("% of Sales with Vendor"), Value1:=Range("B1").Value
End Sub
A1 is where you had the value 2. The Scroll bar should have Cell Link $A$1. However, you Macro reference B1... the place where you divide by ten to be in the proper range of the % of Sales with Vendor values.
Of course, you assign the macro to the Scroll bar.
When you change the scroll bar, it changes A1, and B1, and tells the Macro to execute a Value Filter, using the value in B1. You have thus created a SLIDER, because no you can just click or slide through the scroll bar values (PS. A scroll bar with the long edge horizontal, is a slider)