Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA access to Active X Scroll Bar


I have a chart worksheet that pulls data from a data worksheet. The
number of records changes frequently so I am trying to make the chart
interactive. I have scrollbars that let me change the charted number
of records the starting and ending displayed records and the number of
sigma in the contol limits and the colum of data graphed in the middle.
I can not get the MAX value to change using the named range in the
scrollbar properties nor the VBA. The scroll bars were added with the
following code. I have named ranged for all the MAX values. I
currently delete and recreate the bars when new data is posted but that
is not what i want to have to do. i tried to access the scrollbars with
code and change the .max = but could not get the code to recognize the
control. Help me please. Thak you in advance.

Private Sub Add_Bars()
Dim OLE As OLEObject
'Adds a Scrollbar for fun
Dim mLeft, mWidth, mHeight, mtop As Double
mLeft = 100
mWidth = 526.5
mHeight = 12.75

mtop = 536.5
Set OLE =
ActiveSheet.OLEObjects.Add(ClassType:="Forms.Scrol lBar.1", Left:=mLeft,
Top:=mtop, Width:=mWidth, Height:=mHeight)
With OLE
..Object.Min = 2
..Object.Max = Range("N3").Value
..LinkedCell = "ZoomVal"
..Object.Orientation = 1
..Locked = True
..Shadow = True
..Object.LargeChange = 10
..Name = "ZBar"
End With

mtop = 549.75
Set OLE =
ActiveSheet.OLEObjects.Add(ClassType:="Forms.Scrol lBar.1", Left:=mLeft,
Top:=mtop, Width:=mWidth, Height:=mHeight)
With OLE
..Object.Min = 1
..Object.Max = Range("N4").Value
..LinkedCell = "ScrollVal"
..Object.Orientation = 1
..Locked = True
..Shadow = True
..Object.LargeChange = 10
..Name = "SBar"
End With
mtop = 563.25
Set OLE =
ActiveSheet.OLEObjects.Add(ClassType:="Forms.Scrol lBar.1", Left:=mLeft,
Top:=mtop, Width:=mWidth, Height:=mHeight)
With OLE
..Object.Min = 4
..Object.Max = Range("N5").Value
..LinkedCell = "OffsetVal"
..Object.Orientation = 1
..Locked = True
..Shadow = True
..Object.LargeChange = 1
..Name = "DBar"
End With
mtop = 576.5
Set OLE =
ActiveSheet.OLEObjects.Add(ClassType:="Forms.Scrol lBar.1", Left:=mLeft,
Top:=mtop, Width:=mWidth, Height:=mHeight)
With OLE
..Object.Min = 1
..Object.Max = Range("N6").Value
..LinkedCell = "CntrlLmtVal"
..Object.Orientation = 1
..Locked = True
..Shadow = True
..Object.LargeChange = 1
..Name = "SigmaBar"
End With

Worksheets("chart").Activate
End Sub

Private Sub Workbook_Open()
Worksheets("Chart").Activate
Worksheets("Chart").Range("N3").Value =
Application.WorksheetFunction.CountA(Worksheets("D ata").Range("A1:A65536"))
Worksheets("Chart").Range("N4").Value =
Application.WorksheetFunction.CountA(Worksheets("D ata").Range("A1:A65536"))
Worksheets("Chart").Range("N5").Value =
Application.WorksheetFunction.CountA(Worksheets("D ata").Range("A1:IV1"))
End Sub


--
CodeJunky
------------------------------------------------------------------------
CodeJunky's Profile: http://www.excelforum.com/member.php...o&userid=28896
View this thread: http://www.excelforum.com/showthread...hreadid=486462

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default VBA access to Active X Scroll Bar

I'm not sure if I understand, but...

You have a Data worksheet that allows users to enter more and more stuff. You
want the Max for some scrollbars on sheet Chart to change when the number of
entries changes (increases or decreases)??

If that's close, you could use a worksheet event that adjusts the maximum value
for the scroll bar.

I'm sure I didn't use the correct ranges for each max, but it'll give you an
idea.

Rightclick on the Data Worksheet tab. Select view code and paste this into the
code window:

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count 1 Then Exit Sub
If Intersect(Target, Union(Me.Range("a:a"), Me.Range("1:1"))) Is Nothing
Then
Exit Sub
End If

With Worksheets("Chart")
.ZBar.Max = Application.CountA(Me.Range("a:a"))
.SBar.Max = Application.CountA(Me.Range("1:1"))
.DBar.Max = Application.CountA(Me.Range("a:a"))
End With
End Sub

It looks for changes in column A or row 1. (I didn't guess at SigmaBar.)



CodeJunky wrote:

I have a chart worksheet that pulls data from a data worksheet. The
number of records changes frequently so I am trying to make the chart
interactive. I have scrollbars that let me change the charted number
of records the starting and ending displayed records and the number of
sigma in the contol limits and the colum of data graphed in the middle.
I can not get the MAX value to change using the named range in the
scrollbar properties nor the VBA. The scroll bars were added with the
following code. I have named ranged for all the MAX values. I
currently delete and recreate the bars when new data is posted but that
is not what i want to have to do. i tried to access the scrollbars with
code and change the .max = but could not get the code to recognize the
control. Help me please. Thak you in advance.

Private Sub Add_Bars()
Dim OLE As OLEObject
'Adds a Scrollbar for fun
Dim mLeft, mWidth, mHeight, mtop As Double
mLeft = 100
mWidth = 526.5
mHeight = 12.75

mtop = 536.5
Set OLE =
ActiveSheet.OLEObjects.Add(ClassType:="Forms.Scrol lBar.1", Left:=mLeft,
Top:=mtop, Width:=mWidth, Height:=mHeight)
With OLE
Object.Min = 2
Object.Max = Range("N3").Value
LinkedCell = "ZoomVal"
Object.Orientation = 1
Locked = True
Shadow = True
Object.LargeChange = 10
Name = "ZBar"
End With

mtop = 549.75
Set OLE =
ActiveSheet.OLEObjects.Add(ClassType:="Forms.Scrol lBar.1", Left:=mLeft,
Top:=mtop, Width:=mWidth, Height:=mHeight)
With OLE
Object.Min = 1
Object.Max = Range("N4").Value
LinkedCell = "ScrollVal"
Object.Orientation = 1
Locked = True
Shadow = True
Object.LargeChange = 10
Name = "SBar"
End With
mtop = 563.25
Set OLE =
ActiveSheet.OLEObjects.Add(ClassType:="Forms.Scrol lBar.1", Left:=mLeft,
Top:=mtop, Width:=mWidth, Height:=mHeight)
With OLE
Object.Min = 4
Object.Max = Range("N5").Value
LinkedCell = "OffsetVal"
Object.Orientation = 1
Locked = True
Shadow = True
Object.LargeChange = 1
Name = "DBar"
End With
mtop = 576.5
Set OLE =
ActiveSheet.OLEObjects.Add(ClassType:="Forms.Scrol lBar.1", Left:=mLeft,
Top:=mtop, Width:=mWidth, Height:=mHeight)
With OLE
Object.Min = 1
Object.Max = Range("N6").Value
LinkedCell = "CntrlLmtVal"
Object.Orientation = 1
Locked = True
Shadow = True
Object.LargeChange = 1
Name = "SigmaBar"
End With

Worksheets("chart").Activate
End Sub

Private Sub Workbook_Open()
Worksheets("Chart").Activate
Worksheets("Chart").Range("N3").Value =
Application.WorksheetFunction.CountA(Worksheets("D ata").Range("A1:A65536"))
Worksheets("Chart").Range("N4").Value =
Application.WorksheetFunction.CountA(Worksheets("D ata").Range("A1:A65536"))
Worksheets("Chart").Range("N5").Value =
Application.WorksheetFunction.CountA(Worksheets("D ata").Range("A1:IV1"))
End Sub

--
CodeJunky
------------------------------------------------------------------------
CodeJunky's Profile: http://www.excelforum.com/member.php...o&userid=28896
View this thread: http://www.excelforum.com/showthread...hreadid=486462


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA access to Active X Scroll Bar


I was trying to figure out the Active X syntax for accessing the
controls values in VBA. I figured it out by Googling a similar
problem. Some of the Object attributes are in themselves object
attributes. Just means that you have to use object twice in a row to
drill into those values. Like object.object.max = number


This is what I ended up doing incase someone else runs into a similar
problem and needs the answer...


Code:
--------------------
Private Sub Workbook_Open()

Application.ScreenUpdating = False
Dim maxrow As Long
maxrow = Application.WorksheetFunction.CountA(Worksheets("D ata").Range("d:d"))
'msgbox maxrow
Dim ws As Worksheet
Dim obj As OLEObject
' Save a reference to Sheet 1.
Set ws = Sheets("Chart")
ws.Activate
ws.Range("N3").Value = maxrow
ws.Range("N4").Value = maxrow
ws.Range("N5").Value = Application.WorksheetFunction.CountA(Worksheets("D ata").Range("A1:IV1")) - 4 ' delete the header space

' List information about OLE objects.
' MsgBox "Number of OLEObjects = " & ws.OLEObjects.Count
' Loop through the OLE objects.
On Error Resume Next
next_row = 2
For Each obj In ws.OLEObjects
With obj
If .Name = "ZBar" Then
.Object.Max = ws.Range("N3").Value
End If
If .Name = "SBar" Then
.Object.Max = ws.Range("N4").Value
End If
If .Name = "DBar" Then
.Object.Max = ws.Range("N5").Value
End If
If .Name = "SigmaBar" Then
End If
' MsgBox " NAME: " & .Name & vbCr & " MIN: " & .Object.Min & vbCr & " MAX: " & .Object.Max & vbCr & " Linked Cell: " & .LinkedCell
End With
' Move to the next row.
Next obj

Set ws = Sheets("Data") ' add header info for chart constants
ws.Range("A2:A" & maxrow).Formula = "=B2+Chart!$B$6*STDEV(OFFSET($D$2:$D$65536,,Offset Val,,))"
ws.Range("b2:b" & maxrow).Formula = "=AVERAGE(OFFSET($D$2:$D$65536,,OffsetVal,,))"
ws.Range("c2:c" & maxrow).Formula = "=B2-Chart!$B$6*STDEV(OFFSET($D$2:$D$65536,,OffsetVal,, ))"
Sheets("Data").Select
Set ws = Sheets("Chart")
ws.Activate
Application.ScreenUpdating = True
End Sub
--------------------


--
CodeJunky
------------------------------------------------------------------------
CodeJunky's Profile: http://www.excelforum.com/member.php...o&userid=28896
View this thread: http://www.excelforum.com/showthread...hreadid=486462

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Screen does not scroll as active cell moves down the page KimC Excel Discussion (Misc queries) 3 May 8th 07 06:45 PM
Preventing scroll outside active area Ben Excel Discussion (Misc queries) 2 October 29th 06 05:26 PM
how to scroll through active cells instead of entire worksheet mark smith Excel Discussion (Misc queries) 2 March 13th 06 02:29 AM
Scroll with active input box Harley Excel Programming 1 September 19th 05 03:20 PM
Cursor keys move active cell or scroll screen, how do I select whi Rob Croft Excel Discussion (Misc queries) 1 June 18th 05 11:51 PM


All times are GMT +1. The time now is 10:18 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"