|
-
Mar 30th, 2005, 12:01 PM
#1
Thread Starter
New Member
onchange + option button
Hello!
I have used in VBA (excel 2000) 3 option buttons, which are grouped. Currently, one of them is clicked and the data connected to it are correct.
The problem is that if I make a change in a cell, the data are NOT re-calculated. I have to click another option button, and then re-click the one I want and only then the data become correct again.
So the point is: Is there a way to make the option button to re-calculate the data, whenever ANY change occurs in the current sheet? Something like "onchange"...
Please help !!
Thanks!!
-
Mar 30th, 2005, 12:43 PM
#2
Re: onchange + option button
Welcome to the Forums.
I would need to see some code to be able to optimize it because depending how your calculations are I could
suggest a couple of different methods.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Mar 31st, 2005, 01:44 AM
#3
Thread Starter
New Member
Re: onchange + option button
Well, there are three OptionButtons which call the Sub fetchData. This Sub copies the values of 5 cells to other 5 cells. Its pameters are four. The first two indicate the cells (by row+column), where the data must be pasted. The other two parameters indicate the cells (by row+column again) from where the data are copied.
What I want is to copy and paste the data whenever a change occurs. If I make a change to the cells from where the data are copied, no change occurs to the cells where the data are pasted. It works only if I re-click the button.
Thanks a lot!
CODE:
Private Sub fetchData(toRow, toCol, fromRow, fromCol)
toRow = Range("rev1").Row + toRow
toCol = Range("rev1").Column + toCol
For i = 0 To 4
Cells(toRow + i, toCol) = Cells(fromRow, fromCol + i)
Next i
End Sub
Private Sub OptionButton1_Click()
Call fetchData(0, 0, Range("bas1").Row, Range("bas1").Column)
End Sub
Private Sub OptionButton2_Click()
Call fetchData(0, 0, Range("six1").Row, Range("six1").Column)
End Sub
Private Sub OptionButton3_Click()
Call fetchData(0, 0, Range("phon1").Row, Range("phon1").Column)
End Sub
-
Mar 31st, 2005, 11:24 AM
#4
Re: onchange + option button
Looking through the code I would leave the option buttons code since you want to see an update whenever you
click a different button. I would make use of the SelectionChange event behind the Sheet. This event fires
everytime a different cell gets the focus. So if you enter a new value in a cell and press enter the focus automatically
changes to the cell below, thus in effect firing the SelectionChange event and in there you can call your fetchData
procedure. Note it contains a target range object that may come in handy.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Apr 1st, 2005, 05:46 AM
#5
Thread Starter
New Member
Re: onchange + option button
Thanks a lot!
It works!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|