I am almost a newbie for Excel VBA.
I am trying to display values of some cells from a worksheet on the UserForm2 and unload the form when user clicks the CommandButton1.
To avoid building a class for my controls, I am starting with a draft UserForm where all the components I will need are placed on it.
I set the positions of the text boxes, fill them in, set the position of the CommandButton1. These are all Ok, all shows up as expected/planned.
when I click the CommandButton1 on form I hear a "Ding" and the "clicked CB1" message - which I expect to see - is not displayed.
What is that I am doing wrong or what is missing?
Option Explicit
Public leftOfForm As Long
Public topOfForm As Long
Public widthOfForm As Long
Public heightOfForm As Long
' ***********************************
Dim numInfoMessages As Long
Dim heightBox As Long
Dim lengthTextbox As Long
Dim lengthCommandButton As Long
Dim numberOfScreenRows As Long
Dim horizantalPadding As Long
Dim verticalPadding As Long
Dim indexLoop As Integer
Dim contr As Control
Dim theFontSize As Integer
Public Sub CommandButton1_Click()
'
' Just to confirm it is ok --- current userform will be unloaded
'
MsgBox "clicked CB1"
End Sub
Public Sub UserForm_initialize()
'
' Save forms current info - not needed in fact
'
theFontSize = 12
leftOfForm = UserForm2.Left
topOfForm = UserForm2.top
widthOfForm = UserForm2.Width
heightOfForm = UserForm2.Height
numInfoMessages = 6
'
' Calculate userform size based on number of lines to be displayed
'
heightBox = 25
lengthTextbox = 500
lengthCommandButton = 90
verticalPadding = 20
horizantalPadding = 15
numberOfScreenRows = (numInfoMessages + 1) * 2 + 1
'
' Resize form according to the results
'
UserForm2.Width = horizantalPadding * 3 + lengthTextbox + 10
UserForm2.Height = verticalPadding * (numberOfScreenRows + 2)
UserForm2.top = 0
UserForm2.Left = 0
'
' Fill in and allocate the text boxes
'
indexLoop = 1
For Each contr In UserForm2.Controls
If TypeName(contr) = "TextBox" Then
contr.top = (indexLoop) * 2 * verticalPadding
contr.Left = horizantalPadding
contr.Width = lengthTextbox
contr.Height = heightBox
contr.BorderStyle = 1
contr.Text = ThisWorkbook.Worksheets(ThisWorkbook.messagesPageName).Range("B" & indexLoop + 1).Value
contr.WordWrap = False
contr.MultiLine = False
contr.Font.Size = theFontSize
indexLoop = 1 + indexLoop
End If
Next
'
' Allocate the command button
'
For Each contr In UserForm2.Controls
If TypeName(contr) = "CommandButton" Then
contr.top = (indexLoop) * 2 * verticalPadding
contr.Width = lengthCommandButton
contr.Height = heightBox
contr.Width = lengthCommandButton
contr.Left = UserForm2.Width / 2 - contr.Width / 2
contr.top = (indexLoop) * 2 * verticalPadding
contr.Font.Size = theFontSize
End If
Next
End Sub
Related
I create a form dynamically and fill it with check boxes generated based on all column names of the Excel sheet it is launched from.
I add also a command button.
Here is the code put directly on the form:
Option Explicit
Dim cmdArray() As New Class1
Private Sub UserForm_Initialize()
Dim lastCol As Integer
Dim i As Integer
Dim chkBox As MSForms.CheckBox
Dim myButton As Control
lastCol = Worksheets(1).Cells(1, Columns.Count).End(xlToLeft).Column
Me.Height = 500
Me.Width = 600
For i = 1 To lastCol
Set chkBox = Me.Controls.Add("Forms.CheckBox.1", i)
chkBox.Caption = Worksheets(1).Cells(1, i).Value
' chkBox.Name = i
If i Mod 2 = 1 Then
chkBox.Left = 5
chkBox.Top = 5 + (i - 1) * 10
chkBox.Width = 200
Else
chkBox.Left = 250
chkBox.Top = 5 + (i - 2) * 10
chkBox.Width = 200
End If
Next i
i = 1
Set myButton = Me.Controls.Add("Forms.CommandButton.1", "MyButton", False)
With myButton
.Left = 500
.Top = chkBox.Top - 50
.Width = 50
.Caption = "Hide"
.Visible = True
End With
ReDim Preserve cmdArray(1 To i)
Set cmdArray(i).CmdEvents = myButton
Set myButton = Nothing
Me.ScrollBars = fmScrollBarsVertical
Me.ScrollHeight = chkBox.Top + 20
End Sub
The form is generated without issue: all check-boxes and the command button are set correctly.
I am then supposed to select which columns I want to hide from my Excel sheet, and therefore I tick the relevant checkbox. So far so good. Here is the code set is a Class :
Option Explicit
Public WithEvents CmdEvents As MSForms.CommandButton
Private Sub CmdEvents_Click()
Dim i As Integer
Dim cbx As MSForms.Control
Dim colNum As Integer
i = 0
For Each cbx In Me.UserForm1.Controls
If TypeName(cbx) = "CheckBox" Then
If cbx.Value = True Then
colNum = cbx.Name - i
Worksheets(1).Columns(colNum).EntireColumn.Delete
i = i + 1
End If
End If
Next ctrl
End Sub
When I click the button, it is supposed to trigger the hiding of the columns in the Excel sheet, however, I got the following error:
Compile error: Method or data member not found
This error is reported in the code in the Class module, highlighting the term .UserForm1 and if I remove this .UserForm1, then still the same error highlighting the .Controls.
I am not a great specialist of VBA, I manage usually to create simple codes and reusing samples I can find here and there, but this time, I run out of idea (and understanding), so thanks in advance for any help.
I've created a code in VBA to collect data using a multi-page control. In each page, I've added checkboxes dynamically based on rows from the worksheet in Excel and, for each checkbox, there's a textbox and 2 command buttons, just like the image below:
Input Window:
The code to automatically add controls is:
Private Sub UserForm_Initialize()
fmat_disp.Value = 0
fmat_set.Value = 0
'---------------------------------------------------------------------------------------------
'Inspeção de Mecânica
Sheets("Mecânica").Activate
n_anom = Application.WorksheetFunction.CountA(Range("1:1")) - 1
AreasInspecao.mecanica.ScrollHeight = 10 + 18 * (n_anom)
For i = 1 To n_anom
'Selecionar anomalia
Set SelAnom = AreasInspecao.mecanica.Controls.Add("Forms.CheckBox.1", "sel_anom_" & i)
SelAnom.Caption = Worksheets("Mecânica").Cells(1, i + 1)
SelAnom.AutoSize = True
SelAnom.Height = 18
SelAnom.Left = 5
SelAnom.Top = 5 + (SelAnom.Height) * (i - 1)
SelAnom.Tag = i
Same goes to the textbox and plus/minus buttons, only changing the captions.
What I want is:
1) when CHECKBOX is CHECKED, respective TEXTBOX must show 1
2) when MINUS sign is PRESSED, respective TEXTBOX must decrement
3) when PLUS sign is PRESSED, respective TEXTBOX must increment
4) when "Finalizar Inspeção" is PRESSED, all data collected must be sent to Excel, filling a worksheet.
I simply don't know how to link each button/checkbox to your respective textbox without creating a subroutine for each one! I'll have ~500 subroutines....that's impossible to manage manually....
OK here's a rough outline for handling the click events on the checkboxes and buttons.
First two custom classes for capturing the clicks: each of these is very simple - all they do is call a method on the userform with the clicked control as an argument.
'clsCheck
Public WithEvents chk As MSForms.CheckBox
Private Sub chk_Click()
frmExample.HandleClick chk
End Sub
'clsButton
Public WithEvents btn As MSForms.CommandButton
Private Sub btn_Click()
frmExample.HandleClick btn
End Sub
Userform code - my form is named "frmExample".
Note the naming convention which allows groups of controls to be treated as a "unit".
Option Explicit
'These two global collections hold instances of the custom classes
Dim colCheckBoxes As Collection
Dim colButtons As Collection
Private Sub UserForm_Activate()
Const CON_HT As Long = 18
Dim x As Long, cbx As MSForms.CheckBox, t
Dim btn As MSForms.CommandButton, txt As MSForms.TextBox
Dim oCheck As clsCheck, oButton As clsButton
Set colCheckBoxes = New Collection
Set colButtons = New Collection
For x = 1 To 10
t = 5 + CON_HT * (x - 1)
Set cbx = Me.Controls.Add("Forms.CheckBox.1", "cbox_" & x)
cbx.Caption = "Checkbox" & x
cbx.Width = 80
cbx.Height = CON_HT
cbx.Left = 5
cbx.Top = t
colCheckBoxes.Add GetCheckHandler(cbx) '<< save in collection
Set btn = Me.Controls.Add("Forms.CommandButton.1", "btnplus_" & x)
btn.Caption = "+"
btn.Height = CON_HT
btn.Width = 20
btn.Left = 90
btn.Top = t
btn.Enabled = False '<<buttons start off disabled
colButtons.Add GetButtonHandler(btn) '<< save in collection
Set btn = Me.Controls.Add("Forms.CommandButton.1", "btnminus_" & x)
btn.Caption = "-"
btn.Height = CON_HT
btn.Width = 20
btn.Left = 130
btn.Top = t
btn.Enabled = False '<<buttons start off disabled
colButtons.Add GetButtonHandler(btn) '<< save in collection
'no events are captured for the textboxes...
Set txt = Me.Controls.Add("Forms.Textbox.1", "txt_" & x)
txt.Width = 30
txt.Height = CON_HT
txt.Left = 170
txt.Top = t
Next x
End Sub
'All "clicked" controls saved in instances of the custom classes
' get passed here. Handle based on control type/name
Public Sub HandleClick(ctrl As MSForms.Control)
Dim num
num = Split(ctrl.Name, "_")(1) 'which set of controls are we working with?
Dim txt As MSForms.TextBox
'get the matching text box...
Set txt = Me.Controls("txt_" & num)
If ctrl.Name Like "cbox_*" Then
If ctrl.Value Then txt.Value = 1
Me.Controls("btnplus_" & num).Enabled = ctrl.Value
Me.Controls("btnminus_" & num).Enabled = ctrl.Value
ElseIf ctrl.Name Like "btnplus_*" Then
txt.Value = txt.Value + 1
ElseIf ctrl.Name Like "btnminus_*" Then
txt.Value = txt.Value - 1
End If
End Sub
'couple of "factory" functions for the event-handling classes
Private Function GetCheckHandler(cb As MSForms.CheckBox)
Dim rv As New clsCheck
Set rv.chk = cb
Set GetCheckHandler = rv
End Function
Private Function GetButtonHandler(btn As MSForms.CommandButton)
Dim rv As New clsButton
Set rv.btn = btn
Set GetButtonHandler = rv
End Function
Sample file: https://www.dropbox.com/s/k74c08m0zkwn9l7/tmpFormEvents.xlsm?dl=0
I have created a form where I am dynamically creating Textboxes and corresponding Comboboxes along with Combobox change event. Here is the class creating combobox event handler
Option Explicit
Public WithEvents cbx As MSforms.Combobox
Private avarSplit As Variant
Sub SetCombobox(ctl As MSforms.Combobox)
Set cbx = ctl
End Sub
Private Sub cbx_Change()
Dim i As Integer
If cbx.ListIndex > -1 Then
'MsgBox "You clicked on " & cbx.Name & vbLf & "The value is " & cbx.Value
avarSplit = Split(cbx.Name, "_")
'DecessionOnValue
End If
End Sub
And here is the code on the form which is dynamically creating textboxes and Comboboxes
Function AddTextBox(Frame1 As frame, numberOfColumns As Integer)
Dim counter As Integer
Dim i As Integer
Dim TxtBox As MSforms.TextBox
For counter = 1 To numberOfColumns
'Forms.CommandButton.1
Set TxtBox = Frame1.Controls.Add("Forms.TextBox.1")
TxtBox.Name = "tb_" + CStr(counter)
'Bouton.Caption = "Test"
TxtBox.Visible = True
i = Property.TextBoxDisable(TxtBox)
' Defining coordinates TextBox height is 18
If counter = 1 Then
TxtBox.Top = 23
Else
TxtBox.Top = (18 * counter) + 5 * counter
End If
TxtBox.Left = 50
Next counter
End Function
Function Combobox(Frame1 As frame, numberOfColumns As Integer)
Dim counter As Integer
Dim i As Integer
Dim CbBox As MSforms.Combobox
Dim cbx As ComboWithEvent
If pComboboxes Is Nothing Then Set pComboboxes = New Collection
For counter = 1 To numberOfColumns
'Forms.CommandButton.1
Set CbBox = Frame1.Controls.Add("Forms.ComboBox.1")
CbBox.Name = "cb_" + CStr(counter)
i = AddComboboxValues(CbBox)
' Defining coordinates TextBox height is 18
If counter = 1 Then
CbBox.Top = 23
Else
CbBox.Top = (18 * counter) + 5 * counter
End If
CbBox.Left = 150
Set cbx = New ComboWithEvent
cbx.SetCombobox CbBox
pComboboxes.Add cbx
Next counter
i = AddScrollBar(Frame1, counter)
End Function
Combobox event handler is working fine but my problem is that I dont know that how can I copy the text of textbox or enable disable the textbox according to the value selected in the dynamic combobox.
Thanks,
Jatin
you'll use this for example :
Me.Controls("ControlName").Visible = True or instead of Visible you can use enable, disable etc..
I would like to create costum menu button using VBA in my excel 2010 file using predefined excel button that use face id. In my case i would like to use "lock" and "refresh" icon, but doesn`t know the face id for that icon. could anyone show or point me the list of button and face id used in excel 2010?
The following Sub BarOpen() works with Excel 2010, most probably also many other versions also, and generates in the Tab "Add-Ins" a custom, temporary toolbar with drop-downs to show the FaceIDs from 1 .. 5020 in groups of 30 items.
Option Explicit
Const APP_NAME = "FaceIDs (Browser)"
' The number of icons to be displayed in a set.
Const ICON_SET = 30
Sub BarOpen()
Dim xBar As CommandBar
Dim xBarPop As CommandBarPopup
Dim bCreatedNew As Boolean
Dim n As Integer, m As Integer
Dim k As Integer
On Error Resume Next
' Try to get a reference to the 'FaceID Browser' toolbar if it exists and delete it:
Set xBar = CommandBars(APP_NAME)
On Error GoTo 0
If Not xBar Is Nothing Then
xBar.Delete
Set xBar = Nothing
End If
Set xBar = CommandBars.Add(Name:=APP_NAME, Temporary:=True) ', Position:=msoBarLeft
With xBar
.Visible = True
'.Width = 80
For k = 0 To 4 ' 5 dropdowns, each for about 1000 FaceIDs
Set xBarPop = .Controls.Add(Type:=msoControlPopup) ', Before:=1
With xBarPop
.BeginGroup = True
If k = 0 Then
.Caption = "Face IDs " & 1 + 1000 * k & " ... "
Else
.Caption = 1 + 1000 * k & " ... "
End If
n = 1
Do
With .Controls.Add(Type:=msoControlPopup) '34 items * 30 items = 1020 faceIDs
.Caption = 1000 * k + n & " ... " & 1000 * k + n + ICON_SET - 1
For m = 0 To ICON_SET - 1
With .Controls.Add(Type:=msoControlButton) '
.Caption = "ID=" & 1000 * k + n + m
.FaceId = 1000 * k + n + m
End With
Next m
End With
n = n + ICON_SET
Loop While n < 1000 ' or 1020, some overlapp
End With
Next k
End With 'xBar
End Sub
Have a look here:
Face ID's
Its an addin for MS excel. Works for excel 97 and later.
Modified previous answer to create numerous toolbars with sets of 10 icons. Can change code (comment/un-comment) number of toolbars (performance may be slow on slower machines)
The last icon number for Office 2013 that I could find was 25424 for OneDrive
Sub FaceIdsOutput()
' ==================================================
' FaceIdsOutput Macro
' ==================================================
' =========================
Dim sym_bar As CommandBar
Dim cmd_bar As CommandBar
' =========================
Dim i_bar As Integer
Dim n_bar_ammt As Integer
Dim i_bar_start As Integer
Dim i_bar_final As Integer
' =========================
Dim icon_ctrl As CommandBarControl
' =========================
Dim i_icon As Integer
Dim n_icon_step As Integer
Dim i_icon_start As Integer
Dim i_icon_final As Integer
' =========================
n_icon_step = 10
' =========================
i_bar_start = 1
n_bar_ammt = 500
' i_bar_start = 501
' n_bar_ammt = 1000
' i_bar_start = 1001
' n_bar_ammt = 1500
' i_bar_start = 1501
' n_bar_ammt = 2000
' i_bar_start = 2001
' n_bar_ammt = 2543
i_bar_final = i_bar_start + n_bar_ammt - 1
' =========================
' delete toolbars
' =========================
For Each cmd_bar In Application.CommandBars
If InStr(cmd_bar.Name,"Symbol") <> 0 Then
cmd_bar.Delete
End If
Next
' =========================
' create toolbars
' =========================
For i_bar = i_bar_start To i_bar_final
On Error Resume Next
Set sym_bar = Application.CommandBars.Add _
("Symbol" & i_bar, msoBarFloating, Temporary:=True)
' =========================
' create buttons
' =========================
i_icon_start = (i_bar-1) * n_icon_step + 1
i_icon_final = i_icon_start + n_icon_step - 1
For i_icon = i_icon_start To i_icon_final
Set icon_ctrl = sym_bar.Controls.Add(msoControlButton)
icon_ctrl.FaceId = i_icon
icon_ctrl.TooltipText = i_icon
Debug.Print ("Symbol = " & i_icon)
Next i_icon
sym_bar.Visible = True
Next i_bar
End Sub
Sub DeleteFaceIdsToolbar()
' ==================================================
' DeleteFaceIdsToolbar Macro
' ==================================================
Dim cmd_bar As CommandBar
For Each cmd_bar In Application.CommandBars
If InStr(cmd_bar.Name,"Symbol") <> 0 Then
cmd_bar.Delete
End If
Next
End Sub
I put together my own list of button face ID's. I used Excel VBA code to test all the toolface numbers up to 100,000. There were faces for ID numbers up to almost 34,000. Most of these had duplicates, which make them harder to look through. I compared all the faces to each other using a VBA arraylist, and only kept the first instance of each one. I think this file shows all the toolfaces with their numbers, but it only shows each one once:
https://www.dropbox.com/s/7q7y7uf3tuy02uu/FaceID%20Excel%202021.pdf?dl=0
short script writes ten (loop set for 10) FaceID's add. as entry into toolbar Tab "Add-In" and with "Benutzerdefinierte Symbolliste löschen" - you erase this add entry ( mark and right mouse click) - works with excel 2010/2013
Sub FaceIdsAusgeben()
Dim symb As CommandBar
Dim Icon As CommandBarControl
Dim i As Integer
On Error Resume Next
Set symb = Application.CommandBars.Add _
("Symbole", msoBarFloating)
For i = 1 To 10
Set Icon = symb.Controls.Add(msoControlButton)
Icon.FaceId = i
Icon.TooltipText = i
Debug.Print ("Symbole = " & i)
Next i
symb.Visible = True
End Sub
script provides on worksheet name of controls excel 2010/2013
Sub IDsErmitteln()
Dim crtl As CommandBarControl
Dim i As Integer
Worksheets.Add
On Error Resume Next
i = 1
For Each crtl In Application.CommandBars(1).Controls(1).Controls
Cells(i, 1).Value = crtl.Caption
Cells(i, 2).Value = crtl.ID
i = i + 1
Next crtl
End Sub
I found it in this location what i`m looking at
http://support.microsoft.com/default.aspx?scid=kb;[LN];Q213552
The table contain the Control and id (Face Id) used in excel. So for "Refresh" button the face id is 459, but it only work on the id less than 3 digit.
and this generator(by input start face id and end face id) then click show button faces, you get the list of icon on the range (to download it must login first)
http://www.ozgrid.com/forum/showthread.php?t=39992
and this for Ribbon Toolbar
http://www.rondebruin.nl/ribbon.htm
See image for clarity.
I have 5 variables (A, B, C, D and E), each of which can range from 0-100. I need the sum of all these variables to be 100 at all times, not more, not less. However, the way it is set up currently, if I change variable A from 21 to, say, 51, the total becomes 130.
How could I set this up such that if I change one variable, the others could automatically compensate for that increase or decrease, such that the total is always 100?
Use the Slider Change events, so that when one slider changes value the others are scaled so values sum to 100
Example code, using 3 sliders - you can scale it to allow for as many sliders as you want
Private UpdateSlider As Boolean
Private Sub ScaleSliders(slA As Double, ByRef slB As Double, ByRef slC As Double)
Dim ScaleFactor As Double
If (slB + slC) = 0 Then
ScaleFactor = (100# - slA)
slB = ScaleFactor / 2
slC = ScaleFactor / 2
Else
ScaleFactor = (100# - slA) / (slB + slC)
slB = slB * ScaleFactor
slC = slC * ScaleFactor
End If
End Sub
Private Sub ScrollBar1_Change()
Dim slB As Double, slC As Double
' UpdateSlider = False
If Not UpdateSlider Then
slB = ScrollBar2.Value
slC = ScrollBar3.Value
ScaleSliders ScrollBar1.Value, slB, slC
UpdateSlider = True
ScrollBar2.Value = slB
ScrollBar3.Value = slC
UpdateSlider = False
End If
End Sub
Private Sub ScrollBar2_Change()
Dim slB As Double, slC As Double
If Not UpdateSlider Then
slB = ScrollBar1.Value
slC = ScrollBar3.Value
ScaleSliders ScrollBar2.Value, slB, slC
UpdateSlider = True
ScrollBar1.Value = slB
ScrollBar3.Value = slC
UpdateSlider = False
End If
End Sub
Private Sub ScrollBar3_Change()
Dim slB As Double, slC As Double
If Not UpdateSlider Then
slB = ScrollBar1.Value
slC = ScrollBar2.Value
ScaleSliders ScrollBar1.Value, slB, slC
UpdateSlider = True
ScrollBar1.Value = slB
ScrollBar2.Value = slC
UpdateSlider = False
End If
End Sub
Note that sliders data type in integer, so you may need to allow for rounding not summing to exactly 100
Thx Chris for posting your solution. To scale it to six, I've made this. I'm no VBA expert, this code is not yet really clean or great. but it might help someone.
Private UpdateSlider As Boolean
Private Sub ScaleSliders_arr(slider_value As Double, ByRef other_sliders() As Double)
Dim scale_factor As Double
Dim total_other_sliders As Double
Dim element As Variant
Dim i As Integer
Dim other_sliders_arr_length As Long
For Each element In other_sliders
total_other_sliders = total_other_sliders + element
Debug.Print total_other_sliders
Next element
' when all other values are 0
If total_other_sliders = 0 Then
ScaleFactor = (100# - slider_value)
other_sliders_arr_length = ArrayLength(other_sliders)
i = 0
For Each element In other_sliders
other_sliders(i) = ScaleFactor / other_sliders_arr_length
i = i + 1
Next element
Debug.Print other_sliders_arr_length
' When other sliders have >0 as a total sum
Else
ScaleFactor = (100# - slider_value) / total_other_sliders
' Adjust other sliders according to current value
i = 0
For Each element In other_sliders
other_sliders(i) = other_sliders(i) * ScaleFactor
i = i + 1
Next element
End If
End Sub
Private Sub AdjustSliderByMagic(this_slider As Variant)
Dim slider_value As Double
Dim other_sliders() As Double
Dim cell_locations() As Variant
Dim other_sliders_arr_size As Integer
Dim value As Variant
Dim i As Integer
Dim k As Integer
' which cells contain the values - this also determines number of rows
cell_locations = Array("HiddenTable!B2", "HiddenTable!B3", "HiddenTable!B4", "HiddenTable!B5", "HiddenTable!B6", "HiddenTable!B7")
' size of the others is minus 2 because A) counting starts at 0 B) one slider is the current one which is not the other
other_sliders_arr_size = ArrayLength(cell_locations) - 2
' need to size the other sliders array
ReDim other_sliders(other_sliders_arr_size)
' start loops with 0's
i = 0
k = 0
' Determine the value of this slider and of the other sliders
For Each value In cell_locations
If this_slider = cell_locations(i) Then
slider_value = Range(cell_locations(i)).value
Else
other_sliders(k) = Range(cell_locations(i)).value
k = k + 1
End If
i = i + 1
Next value
' use function to determine slider values
ScaleSliders_arr slider_value, other_sliders
UpdateSlider = True
' start loops with 0's
i = 0
k = 0
' change the values of the other sliders
For Each value In cell_locations
If this_slider = cell_locations(i) Then
'do nothing
Else
Range(cell_locations(i)).value = other_sliders(k)
k = k + 1
End If
i = i + 1
Next value
End Sub
Private Sub ScrollBar1_Change()
Dim this_slider As Variant
' what is the connected field of this slider
this_slider = "HiddenTable!B2"
AdjustSliderByMagic (this_slider)
End Sub
Private Sub ScrollBar2_Change()
Dim this_slider As Variant
' what is the connected field of this slider
this_slider = "HiddenTable!B3"
AdjustSliderByMagic (this_slider)
End Sub
Private Sub ScrollBar3_Change()
Dim this_slider As Variant
' what is the connected field of this slider
this_slider = "HiddenTable!B4"
AdjustSliderByMagic (this_slider)
End Sub
Private Sub ScrollBar4_Change()
Dim this_slider As Variant
' what is the connected field of this slider
this_slider = "HiddenTable!B5"
AdjustSliderByMagic (this_slider)
End Sub
Private Sub ScrollBar5_Change()
Dim this_slider As Variant
' what is the connected field of this slider
this_slider = "HiddenTable!B6"
AdjustSliderByMagic (this_slider)
End Sub
Private Sub ScrollBar6_Change()
Dim this_slider As Variant
' what is the connected field of this slider
this_slider = "HiddenTable!B7"
AdjustSliderByMagic (this_slider)
End Sub
Function ArrayLength(arr As Variant) As Long
On Error GoTo eh
' Loop is used for multidimensional arrays. The Loop will terminate when a
' "Subscript out of Range" error occurs i.e. there are no more dimensions.
Dim i As Long, length As Long
length = 1
' Loop until no more dimensions
Do While True
i = i + 1
' If the array has no items then this line will throw an error
length = length * (UBound(arr, i) - LBound(arr, i) + 1)
' Set ArrayLength here to avoid returing 1 for an empty array
ArrayLength = length
Loop
Done:
Exit Function
eh:
If Err.Number = 13 Then ' Type Mismatch Error
Err.Raise vbObjectError, "ArrayLength" _
, "The argument passed to the ArrayLength function is not an array."
End If
End Function