Click here to Skip to main content
15,892,809 members

How do I get a group of checkboxes to stay where they are moved to using vb code?

Smithk32 asked:

Open original thread
VB
Sheets(appServer & "chart").Select
ActiveChart.ChartTitle.Select
ActiveChart.ChartTitle.Text = appServer
ActiveChart.PlotArea.Select
Selection.Width = 434.944
ActiveChart.Legend.Select
ActiveChart.ChartArea.Select
ActiveChart.Legend.Select
Selection.Left = 466.86
Selection.Top = 62.544


This is my code to shrink the plot area of a chart in order to move the legend over to make room for checkboxes to toggle the display of each series. The program works great until I save and reopen it. When it is reopened the checkboxes end up on top of the legend and I can easily fix that every time I reopen the file, but I would rather just fix the issue in my code.Thanks in advance for any help.

VB
Dim chartRangeStart As Integer
Dim chartRangeEnd As Integer
Dim serverNum As Integer
Dim numOfServers As Integer
Dim topOfCheckbox As Integer
Dim appServerNum As Integer
Dim appServer As String

chartRangeStart = 51
chartRangeEnd = 98
numOfServers = 23
serverNum = 1
topOfCheckbox = 56
appServerNum = 0
appServer = server
   
   Do While serverNum <= numOfServers
' adds a checkbox for each appServer in an array
    ActiveChart.CheckBoxes.Add(4529766, 485607, 685185.75, 685896.75).Select
    Selection.Characters.Text = ServerNamesArray(appServerNum)
    Selection.ShapeRange.Fill.Visible = msoTrue
    Selection.ShapeRange.Fill.Solid
    Selection.ShapeRange.Fill.ForeColor.SchemeColor = 9
    Selection.ShapeRange.Fill.Transparency = 0#
    Selection.ShapeRange.Line.Weight = 0.75
    Selection.ShapeRange.Line.DashStyle = msoLineSolid
    Selection.ShapeRange.Line.Style = msoLineSingle
    Selection.ShapeRange.Line.Transparency = 0#
    Selection.ShapeRange.Line.Visible = msoFalse
      With Selection
        .Value = xlOff
        .LinkedCell = appServer & "!$" & ColumnArray(appServerNum) & "$2"
        .Display3DShading = False
      End With

' moves the checkbox to where I want it (until I save and reopen)
    Selection.ShapeRange.IncrementLeft 465#
    Selection.ShapeRange.IncrementTop topOfCheckbox
    Selection.ShapeRange.ScaleWidth 2#, msoFalse, msoScaleFromTopLeft
    Selection.ShapeRange.ScaleHeight 1#, msoFalse, msoScaleFromTopLeft
    topOfCheckbox = topOfCheckbox + 13
     
    Loop


This is the code that adds the checkboxes to the chart.
Tags: Visual Basic, Microsoft Excel

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900