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!
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!