|
-
Jul 10th, 2005, 12:17 PM
#1
Thread Starter
Hyperactive Member
*Resolved* Excel & "On SelectionChange" question
I have a query I am hoping you can help me with.
I have an Excel chart and I want the user to be able to change to range of the x-axis to any number between 2 and 100. They do this simply by entering a number in a cell and the chart x-axis should automatically update so that the Max. Number for the x-axis equals the user input value.
For the sake of argument suppose that the cell that the user needs to enter the number in is cell A1.
I already have the code that changes the x-axis, which is as follows:
Code:
With ActiveSheet
.ChartObjects("Chart 1").Chart.Axes(xlCategory).MaximumScale = Range("A1")
End With
The problem is I don't know how to get the spreadsheet to execute this piece of code. I thought that the SelectionChange event might be the one I need but I can't get it to work.
Also, ideally I only want the spreadsheet to do anything if cell A1 only is changed i.e. it doesn't need to update the chart x-axis if some other cell is changed.
So ideally I need code that says:
Code:
If Cell A1 is changed then make the x-axis of Chart 1 equal the new value
Thanks in advance
-Rob
Last edited by TheRobster; Jul 10th, 2005 at 04:15 PM.
http://www.sudsolutions.com
-
Jul 10th, 2005, 12:40 PM
#2
Re: Excel & "On SelectionChange" question
Either should do it. Your choice .
VB Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A$1" Then
'Update chart
End If
End Sub
'Or
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = "$A$1" Then
'Update chart
End If
End Sub
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 
-
Jul 10th, 2005, 01:33 PM
#3
Fanatic Member
Re: Excel & "On SelectionChange" question
Note for what RobDog said. If I remember correctly the _Change sub will only fire after the user exits the cell that is being changed.
To elaborate... say you type 50 in the cel and leave the cursor sitting there.. it wont fire the event, but if you move the cursor to another cell then the event fires if it was changed from its previous value.
-
Jul 10th, 2005, 01:42 PM
#4
Re: Excel & "On SelectionChange" question
Correct and good description of the event. 
You could also add a menu or toolbar button to do your chart refresh if you want to also.
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 
-
Jul 10th, 2005, 04:17 PM
#5
Thread Starter
Hyperactive Member
Re: Excel & "On SelectionChange" question
Cheers for the replies guys. 
 Originally Posted by RobDog888
You could also add a menu or toolbar button to do your chart refresh if you want to also. 
No, the methods you outlined earlier will be fine. Before I posted my query on here I was actually thinking about using a button labelled "Update" or something similar and binding this to a macro which would update the chart x-axis but your solution is more elegant.
-Rob
http://www.sudsolutions.com
-
Jul 10th, 2005, 06:34 PM
#6
Re: *Resolved* Excel & "On SelectionChange" question
As always we are glad to have helped. 
Btw, did you see that we have a new way to do a simple "[RESOLVED]"? Its from the Thread Tools menu > Mark Thread Resolved.
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 
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
|