Option Button & Macro
Hi All,
I've created several Option Buttons (activeX) on my Excel sheets.
I'm creating a generic hide-when function that uses the Option Button's name as reference. Now, I cannot read the name of the Option Button that user selected. I want something like me.value. I don't want to use me.OptionButton1.Name (thats not generic)
here's the sub the button should call, where tempname is the name of the Option Button;
//Caller:
Private Sub P02_Q01_Y_Click()
Call ShowHideQuestions(Me.Name) <-- doesnt work.. returns sheet name
End Sub
Sub ShowHideQuestions(tempName As String)
On Error GoTo ErrHandler
'Dim tempName As String
Dim rangeName As String
Dim XrangeName As String
Dim XrangeName_XTRA As String
Dim ShowHide As String
Dim blProtected As Boolean
Dim ThisRow As Long
Dim lngCounter As Long
Dim lngLastRow As Long
Application.ScreenUpdating = False
blProtected = False
'tempName = Application.Caller
rangeName = Left(tempName, 7)
ShowHide = Right(tempName, 1)
lngLastRow = ActiveSheet.Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
ThisRow = 1
If ActiveSheet.ProtectContents = True Then
blProtected = True
ActiveSheet.Unprotect (pwd)
End If
Select Case ShowHide
Case Is = "S" 'Special Case
Exit Sub
Case Is = "Y" 'Yes Flag
Range(rangeName).Rows.RowHeight = 16.5
Case Is = "N" 'No Flag
Range(rangeName).Rows.RowHeight = 0
Case Is = "X" 'X show first option hide second
Range(rangeName & "_X").Rows.RowHeight = 16.5
Range(rangeName & "_Z").Rows.RowHeight = 0
Case Is = "Z" 'X hide first option show second
Range(rangeName & "_X").Rows.RowHeight = 0
Range(rangeName & "_Z").Rows.RowHeight = 16.5
Case Else
Exit Sub
End Select
Dim strCellValue
Dim strUserCellValue
Dim intInString
Dim strBlockVal As String
Dim strHiddenBlock As String
For lngCounter = 1 To lngLastRow
strCellValue = (Range("A" & lngCounter).Value)
intInString = InStr(UCase(strCellValue), UCase(rangeName))
If intInString > 0 Then
'MsgBox UCase(Mid(strCellValue, 2))
If Left(UCase(strCellValue), 5) = UCase("XOPT_") Then
strUserCellValue = (Range("B" & lngCounter).Value)
strBlockVal = strBlockVal & strUserCellValue
strCellValue = strCellValue & "_X"
' If strHiddenBlock = "" Then
' strHiddenBlock = strCellValue
' End If
If ShowHide = "Y" And strUserCellValue <> "" Then
Range(strCellValue).Rows.RowHeight = 12.75
Else
Range(strCellValue).Rows.RowHeight = 0
End If
End If
End If
Next
If blProtected = True Then
ActiveSheet.Protect (pwd)
End If
Application.ScreenUpdating = True
Exit Sub
ErrHandler:
Application.ScreenUpdating = True
MsgBox Err & "' " & Err.Description
Exit Sub
End Sub
Plz Help
|