Scenario
I have an excel worksheet where I am using a certain cell (say C3) as a button functionality: Whenever the cell is selected (SelectionChange), a certain function is executed.
In order to be able to click the cell several times in a row, after performing the desired functionality I am setting the selection back to a neutral cell (say A1). This way, C3 can be selected again and the function can run again.
Problem
I would like to click the button cell (C3) several times in a row in quick succession. However, when I click it twice shortly in a row (double-click), it actually enters into edit mode for the neutral cell (A1).
I am aware of the option Cancel = True in the BeforeDoubleClick event handler. However, this doesn't work for me because it cancels the entire event altogether: With Cancel = True the second click will simply be cancelled altogether and my desired function simply won't run.
Question
Any smart ideas on how to prevent the double click while at the same time still interpreting the second click as just a normal single click?
Just expanding my comment to an answer:
Can you disable Allow editing directly in cells on File > Options > Advanced > Editing Options? Although this is a non-programming approach, it may be the simplest solution to your problem.
You could try cell security. Do not allow locked cells to be selected and use VBA to turn security on or off.
The cell could be unlocked by default and a transparent label could lock the cell on mouse rollover.
Related
i want to run my code such that it can pause and allow user to filter a column and then the code continues to run. Is this possible?
I thought of using inputbox to prompt user to key in the name. However, this is not feasible because user may not be able to remember the exact name. It will be more convenient for the user to look at the drop down list and select the name he wants to filter.
Please advice me how can this be done. Thank you
You can't stop a VBA macro to wait until an action was done within Excel.
I see the following possibilities:
a) Create a small userform showing a dropdown. If you show that form modal (that is the default), the macro will pause and wait until the form is closed. However, you will need to implement code to fill up the dropdown and to set the filter by code.
b) End your macro and implement an event that fires when the user changes the filter. There is no "On filter change"-event in Excel, but there is a work around: Excel VBA Filter Change event handler. Put the second part of your code into a separate sub and call that from the event handler.
I want to make an ajax like search in excel 2003 vba. I found a script that can catch button presses.Here -> Is there any event that fires when keys are pressed when editing a cell?
The problem is how to get the text you are currently editing? It will be put in the Cell.Value only after you hit enter.
I was thinking you know what the cell.Value was when you started editing and you can apply the button pressies to it. This would work till you don't use the mouse to change the cursor position.
If you're able to detect the key-presses, you could just build up a string of each character pressed until the enter key is pressed, although you might have to handle special keys like line-breaks, arrow-keys, insert, delete and backspace, and Cut/Copy/Paste.
I am looking for a simple macro I could activate with a form control button that would clear all of the form control option buttons on my sheet.
I have lists of options for industrial part specifications, of which only one may be selected per section. However, once one is selected, the form control option button stays filled in. I previously circumvented this by using checkboxes, where if you click the box again it will remove the check mark. However once I learned that I was to create the form in such a way that only one option could be selected per section, (for ease of use in case a less computer minded person were to use it) it became clear that option buttons were the right way to go.
So I need a simple macro that I can activate with a button that will clear these option buttons all to blank, as if none were selected. I have looked and tried some strings of code, but none have worked so far. Perhaps I am missing something obvious or looking for the wrong thing, but I dont think I am.
I have checked the following pages and tried their code:
http://www.mrexcel.com/forum/excel-questions/689865-how-clear-all-checkboxes-option-buttons-list-boxes-form-3.html
Re-setting all option buttons at once
http://www.excel-easy.com/vba/examples/option-buttons.html
I feel like this should be simple. A VBA macro code that will reset the FORM CONTROL Option Buttons to blank (which I believe is the false state?). No need to worry about having specific ranges to clear; one button to reset the sheet will do perfectly.
Thanks in advance for any help.
Cycle through the Shapes collection:
Sub Reset()
For Each vCtrl In ActiveSheet.Shapes
vCtrl.DrawingObject.Value = False
Next
End Sub
Needing some help attaching an Excel/VBA button on an Excel sheet. I need it to stay in the same position on the screen regardless of how I scroll or zoom. Preferably, I need this on the bottom left or right of the screen.
I have tried adding a button. Then, I right clicked on the button. Clicked on Format Controls -> Properties -> selected Don't Move or Size With Cells. Am I missing something that's making this not work?
Thanks!
I know this post is old, but here's to anyone it could be useful. The VisibleRange property of ActiveWindow can solve this problem. Use something like this:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
With ActiveSheet.OLEObjects("MY_BUTTON'S_NAME")
.Top = ActiveWindow.VisibleRange.Top + ActiveWindow.VisibleRange.Height - 5
.Left = ActiveWindow.VisibleRange.Left + ActiveWindow.VisibleRange.Width - .Width - 5
End With
End Sub
Here is the idea that I put across the comment earlier today :) Typically we can get a Floating User Form by setting the Modal property of the form to be 0 which is indeed a Modeless state.
Basic Points to consider:
Look & Feel of the form to make it look like a Button (Not show title bar/Not Resizable/
Hidden Close Button etc)
Setting the position of the Button
Which Event should trigger the form-button (WorkBook Open)
What would you do with Form Initialize Event
Whcih Events should keep it stick to the same position alive
Further Points to consider:
You might only want to keep this button vissible for the workbook you are working, and if you open another instance of a workbook, do you still want to keep the button
If you minimize the Excel Window instance, how do you plan to manage the state of the button and keep it visible
Post about keep displaying a form even the workbook is minimized.
One other great reference I happend to see, (little bit technical) but worth the shot - at least to get to know the certain properties/methods that you could make use: Extending VBA User Form Control.
The article include the following info, and please note the last line as well :)
They give you access to capabilities that are not available from VBA or from the objects (UserForms, Workbooks, etc.,) that make up a VBA Project. When you call an API, you are bypassing VBA and calling directly upon Windows. This means that you do not get the safety mechanisms such as type checking that VBA normally provides. If you pass an invalid value to an API or (a very common mistake) use a ByRef parameter instead of a ByVal parameter, you will most likely completely and immediately crash Excel and you will lose all your unsaved work. I recommend that until you are confident that your API calls are solid you save your work before calling an API function.
Add new Row on the beginning of your WorkSheet and set your button on it, then:
Freeze Top Row
Right click → properties → placement → change to 3.
Please find the following workbook https://dl.dropbox.com/u/69651453/fff.xlsm , is there a way we can instead use checkboxes? In the sense that one can de-check and the copied rows for that button are deleted and the gap closed again?
Also is there a way to disable check-boxes, depending on values in the sheet. In our case, if ANY invalid data is detected in the sheet, the checkboxes are greyed out... or blocked somehow.
Any Active X solutions would be appreciated too.
Thanks
If you use checkboxes and bind them to that specific cell then treat the cell's click event as you are the button click event it should function the same way.