Hidden Dan
Board Regular
- Joined
- Dec 7, 2016
- Messages
- 63
Hello all,
I'm new here and though pretty well experienced in data mining and spreadsheets, I'm very poor in programming.
For large spreadsheets I use quite some 'Grouping' actions to make it all more compact. The Groupings are called from a button and the name of the button is such that it will tell the macro how many rows should be grouped and which one is the starting row. ('btn_20_5_H' will hide 5 rows starting at row 20 ).
Button name can be like 'btn_20_5_H and executes script below:
Sub ShowHideRows()
Dim arr
'split the calling button name into an array
' (array will be zero-based)
arr = Split(Application.Caller, "_")
'**EDIT** check array is expected size...
If UBound(arr) <> 3 Then Exit Sub
If IsNumeric(arr(1)) And IsNumeric(arr(2)) Then
With ActiveSheet '
'arr(1) determines start row
'arr(2) determines # of rows
'arr(3) determines if rows are hidden or not
.Cells(arr(1), 1).Resize(arr(2), 1).EntireRow.Hidden = (arr(3) = "H")
End With
End If
End Sub
Now I got 24 scripts that lock/unlock some cells. These cells are all 'Named Ranges' like Month01, Month02, Month03, etc. Simplified script is like below:
Sub Macro_unlock()
Application.Goto Reference:="Month03"
Selection.Locked = False
Selection.FormulaHidden = False
End Sub
I was trying to create a generic script from the above which integrates the unlock macro. A named button like 'btn_Month01' should execute the unlock for named range Month01 and 'btn_Month02' should do for named range Month02 and so on till Month12.
My original idea is something like this :
Sub LockMonth()
Dim arr as String
'split the calling button name into an array
' (array will be zero-based)
arr = Split(Application.Caller, "_")
'**EDIT** check array is expected size...
If UBound(arr) <> 2 Then Exit Sub
With ActiveSheet '
'arr(1) determines Named Range
Application.Goto Reference:=arr(1)
Selection.Locked = False
Selection.FormulaHidden = False
End With
End Sub
But unfortunately this is not correct programming. I'm not sure where to look but 'Application.Goto Reference:=arr(1)' is most probaly incorrect.
Can I get some help here to reconstruct my Application.Caller Lock script ?
Thanks
Dan
I'm new here and though pretty well experienced in data mining and spreadsheets, I'm very poor in programming.
For large spreadsheets I use quite some 'Grouping' actions to make it all more compact. The Groupings are called from a button and the name of the button is such that it will tell the macro how many rows should be grouped and which one is the starting row. ('btn_20_5_H' will hide 5 rows starting at row 20 ).
Button name can be like 'btn_20_5_H and executes script below:
Sub ShowHideRows()
Dim arr
'split the calling button name into an array
' (array will be zero-based)
arr = Split(Application.Caller, "_")
'**EDIT** check array is expected size...
If UBound(arr) <> 3 Then Exit Sub
If IsNumeric(arr(1)) And IsNumeric(arr(2)) Then
With ActiveSheet '
'arr(1) determines start row
'arr(2) determines # of rows
'arr(3) determines if rows are hidden or not
.Cells(arr(1), 1).Resize(arr(2), 1).EntireRow.Hidden = (arr(3) = "H")
End With
End If
End Sub
Now I got 24 scripts that lock/unlock some cells. These cells are all 'Named Ranges' like Month01, Month02, Month03, etc. Simplified script is like below:
Sub Macro_unlock()
Application.Goto Reference:="Month03"
Selection.Locked = False
Selection.FormulaHidden = False
End Sub
I was trying to create a generic script from the above which integrates the unlock macro. A named button like 'btn_Month01' should execute the unlock for named range Month01 and 'btn_Month02' should do for named range Month02 and so on till Month12.
My original idea is something like this :
Sub LockMonth()
Dim arr as String
'split the calling button name into an array
' (array will be zero-based)
arr = Split(Application.Caller, "_")
'**EDIT** check array is expected size...
If UBound(arr) <> 2 Then Exit Sub
With ActiveSheet '
'arr(1) determines Named Range
Application.Goto Reference:=arr(1)
Selection.Locked = False
Selection.FormulaHidden = False
End With
End Sub
But unfortunately this is not correct programming. I'm not sure where to look but 'Application.Goto Reference:=arr(1)' is most probaly incorrect.
Can I get some help here to reconstruct my Application.Caller Lock script ?
Thanks
Dan