ZOOM makro doesn't work

delpiero

New Member
Joined
Jul 21, 2010
Messages
4
Hallo,
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
Worksheets(sheetname).Select
Worksheets(sheetname).Chartobjects(k).Select





'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

Range("a:a").Select
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")


Range("a1").Select

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

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

Range("a1").Select
ActiveSheet.ScrollBars.Add(Left_Position, Top_Position, cht_width, 10).Name = varname2
ActiveSheet.ScrollBars(varname2).Select

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
Else
xposi = 0
yposi = yposi + 500
End If

Loop
xposi = 0
yposi = 0

Next


End Sub





Thanking you in anticipation!
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
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.
Code:
Application.RollZoom = True
 
Upvote 0

Forum statistics

Threads
1,214,915
Messages
6,122,217
Members
449,074
Latest member
cancansova

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top