ZOOM makro doesn't work


New Member
Jul 21, 2010
I've a problem! I programmed a ZOOM makro with scrollbars. It should zoom in or out if one ore both of the scrollbars values change. The zooming function doesn't work and an other problem is, that if the programm is started, on every worksheet should be add the two scrollabrs to each chart. My english is not the best, hope you'll understand my problem!

This is my code:

Option Explicit
Private Sub ScrollBar()

Dim ScrollBar As String
Dim chartname As String
Dim a As Integer
Dim b As Integer

Dim a1 As String
Dim b1 As String
Dim x1 As Integer
Dim x2 As Integer
Dim nMaxZeilen As Integer
Dim NewFileName() As String
Dim Min As Double
Dim Max As Double
Dim Chart As String
Dim sheetname As String
Chart = "Chart 1"
Dim Counter As Integer
Dim nMaxZeilen2 As String
Dim varname1, varname2 As String
varname1 = "scrolmin"
varname2 = "scrolmax"
Dim chtobj As ChartObject

Dim xposi As Integer
Dim yposi As Integer
xposi = 0
yposi = 0
Dim Msg As String
Dim n As Integer
Dim ws As Worksheet
Dim iiii As Integer
Dim cht_width As Integer
Dim cht_height As Integer
Dim Top_Position As Integer
Dim Left_Position As Integer
Dim k As Integer
nMaxZeilen = 0

iiii = 1

For Each ws In ActiveWorkbook.Worksheets
n = ws.Chartobjects.Count

k = 0
Do While n > k

sheetname = ActiveSheet.Name
k = k + 1

'For Each chtobj In ActiveWorkbook.Worksheets

chartname = ActiveChart.Name
NewFileName = Split(chartname, " ")
ActiveSheet.Chartobjects(NewFileName(1) & " " & NewFileName(2)).Activate

cht_width = ActiveSheet.Chartobjects(NewFileName(1) & " " & NewFileName(2)).Width
cht_height = ActiveSheet.Chartobjects(NewFileName(1) & " " & NewFileName(2)).Height
Top_Position = ActiveSheet.Chartobjects(NewFileName(1) & " " & NewFileName(2)).Top
Left_Position = ActiveSheet.Chartobjects(NewFileName(1) & " " & NewFileName(2)).Left
iiii = iiii + 1

nMaxZeilen = ActiveSheet.UsedRange.Rows.Count

nMaxZeilen2 = nMaxZeilen

Range("Ij1") = "=min(a4:a" & nMaxZeilen & ")"
a = Range("Ij1")

Range("Ij2") = "=max(a4:a" & nMaxZeilen & ")"
b = Range("Ij2")


ActiveSheet.ScrollBars.Add(Left_Position, Top_Position - 10, cht_width, 10).Name = varname1

With Selection 'von min bis x1
.value = Range("II1") ' = variable durch schieber definiert!!!
.Min = a ' = a
.Max = b ' = x2
.SmallChange = 1
.LargeChange = 10
.LinkedCell = "$II$1"
.Display3DShading = True
End With

ActiveSheet.ScrollBars.Add(Left_Position, Top_Position, cht_width, 10).Name = varname2

With Selection
.value = Range("II2")
.Min = a
.Max = b
.SmallChange = 1
.LargeChange = 10
.LinkedCell = "$II$2"
.Display3DShading = True

End With

a = Range("Ij1")
b = Range("Ij2")

ActiveSheet.Chartobjects(NewFileName(1) & " " & NewFileName(2)).Activate

With ActiveChart.Axes(xlCategory)
.MinimumScale = a '=a
.MaximumScale = b '=b
.MinorUnitIsAuto = True
.MajorUnitIsAuto = True
.Crosses = xlAutomatic
.ReversePlotOrder = False
.ScaleType = xlLinear
.DisplayUnit = xlNone
.HasTitle = True
.AxisTitle.Characters.Text = "Time "
End With

If k < 3 Then
xposi = xposi + 400
xposi = 0
yposi = yposi + 500
End If

xposi = 0
yposi = 0


End Sub

Thanking you in anticipation!

Some videos you may like

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.


Well-known Member
Aug 1, 2010
Doesn't the status bar have a zoom?
So the user can select the chart and use the status bar zoom.
Alternately, on open of the WB, you can set the zoom on mouse roll, assuming the mouse is a roller-mouse.
Application.RollZoom = True

Subscribe on YouTube

Watch MrExcel Video

Forum statistics

Latest member

This Week's Hot Topics

  • Sort code advice please
    Hi, I have the code below which im trying to edit but getting a little stuck. This was the original code which worked fine,columns A-F would sort...
  • SUMPRODUCT with nested If statement
    Hi everyone, Hope you're all well. I'm hoping someone will be able to point me in the right direction with a problem I'm having with a SUMPRODUCT...
  • VBA - simple sort is killing me!
    Hello all! This should be so easy, but not for me, apparently! I have a table of data that can be of varying lengths and widths. My current macro...
  • Compare Two Lists
    I have two Lists and I need to be able to Identify differences between them. List 100 comes from a workbook - the other is downloaded form the...
  • Formula that deducts points for each code I input.
    I am trying to create a formula that will have each student in my class start at 100 points and then for each code that I enter (PP for Poor...
  • Conditional formatting formula required for day of week and a value
    Hi, I have a really simple spreadsheet where column A is the date, column B is the activity total shown as a number and column C states the day of...