January 21st, 2013, 01:37 PM
Selecting Cells with a mouse
I am trying to write a program that promts the user to input a percentage at the start of a program and then prompt the user to select the cells with a mouse that they want to modify (these cells are not in any specific order) and click OK when done. The program would then take the value of each cell (individually) and multiple that by the percentage (I would also like the program to take this number and round down to the nearest number that is divisible by 12). How would the code look in Visual Basic for the mouse click and the math.
January 22nd, 2013, 08:08 AM
What do you mean by "cell". Are you talking about a DataGrid, a FlexGrid, or a MSHFlexGrid?
January 22nd, 2013, 08:12 AM
a cell on an excel spreadshhet
January 22nd, 2013, 10:29 AM
Sorry, can't help you. I have very limited knowledge of using VBA with Excel.
January 22nd, 2013, 05:26 PM
Check the online VBA help in excel and you should a section showing the various mouse events available to your code.
I've never been able to appreciate the sublime arrogance of folks who feel they were put on earth just to save other folks from themselves .." - Donald Hamilton
February 2nd, 2013, 11:34 AM
basic mouse handling
Basic mouse handling is in the sheet code not in the modules, you can access the sheet code by right clicking the sheet tab and selecting View Code
Put this in: -
Right clicks will prompt for a value and double clicks will apply it
Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, _
Cancel As Boolean)
Selection = Selection + xvalue
Sub Worksheet_BeforeRightClick(ByVal Target As Range, _
Cancel As Boolean)
xvalue = InputBox("Value to use", "Hello")
February 6th, 2013, 09:13 AM
Thanks GGriggs...this works awesome!! Now I have another question, is it possible to highlight other cells in the same row as the one that is "double clicked"
February 9th, 2013, 03:13 AM
'get the row and column of your selection
NowRow = selection.row
NowColumn = selection.column
'work out top left corner of what you want to select perhaps
TopLeftCornerRow = NowRow-4
TopLeftCornerColumn= NowColumn -1
'work out bottom right corner of what you want to select perhaps
BottomRightCornerRow = NowRow+7
'Then select it
'as a tip given to me many years ago note the capital letters in the variable names, it makes your code an awful lot easier to read
Last edited by GGriggs; February 9th, 2013 at 03:15 AM.