확인란 가시성 변경이 작동하지 않습니다


3

시트에 행을 숨기는 다음 코드가 있지만 동적으로 생성 된 확인란이 여전히 표시되어 있습니다. 어떤 아이디어?

Private Sub SpinButton1_Change()

Application.ScreenUpdating = False
week = Me.Range("b1").Value
countcell = ActiveSheet.Range("A:A").Cells.SpecialCells(xlCellTypeConstants).Count
For i = 4 To countcell
  pweek = Me.Cells(i, 2).Value    'load the planned week value
  mycont = "ckboxPrintLabels" & i
  If pweek <> week Then
    CheckBoxes(mycont).Visible = False
    Rows(i).EntireRow.Hidden = True
    MsgBox mycont & "= " & ActiveSheet.CheckBoxes(mycont).Visible
  Else
    Rows(i).EntireRow.Hidden = False
    ActiveSheet.CheckBoxes(mycont).Visible = True
  End If
  k = i
Next i
Application.ScreenUpdating = True
End Sub

그래서 현재 시트에 ckboxPrintLabels4에서 16까지가 있습니다. 가시성을 변경하지 못합니다. msgbox가 false에서 가시성을 가지고 있다고보고하지만 ... ???


btw는 Excel 2003이며 확인란 생성을위한 동적 코드는 다음과 같습니다.` '주석에 맞게 스니핑됩니다. cell.Left, _ cell.Top, cell.Width, cell.Height) .LinkedCell = "".Interior.ColorIndex = xlNone .Caption = "".name = "ckboxPrintLabels"& ckbox .Visible = ckbox와 함께 True End = ckbox + 1 다음 Application.ScreenUpdating = True End Sub`
— Onyx

3
[해결됨]을 추가하지 말고 질문 섹션에 답을
— 기입

Sathya .. 그것을 정리 해줘서 고마워. 점수가 낮아서 다시 게시 할 수 없을 때 혼란 스러웠습니다.
— 오닉스

답변:


4

보이는 모든 확인란의 이름이 실제로 ckboxPrintLabelsX 등인지 확인 했습니까?

첫 번째 실행에서 나중에 두 번 주석 처리 된 코드를 분리 할 때 상자의 이름을 올바르게 지정하지 않은 것처럼 코드를 두 번 실행했습니다. 두 번째 실행 은 ckboxPrintLabelsX 제목이있는 확인란을 올바르게 숨겼지만 제목이 다른 다른 확인란 (확인란 1 등)은 여전히 ​​표시되었습니다.

빠른 구글은 http://www.teachexcel.com/excel-help/excel-how-to.php?i=103984 에서 비슷한 문제를 일으킨다 . 이 경우 확인란이 행 숨기기에 쌓이면 맨 위에 다시 표시됩니다.


같은 이름으로 하나 이상의 확인란을 만드는 중에 생성 코드에 오류가 발생했습니다. 이것들은 쌓일 것입니다. 숨기기가 발생했을 때 하나의 컨트롤 집합에만 적용되었습니다.

    Public Sub addcheckboxes(ByVal Lower As String, ByVal Upper As String)
    Dim ws As Worksheet, myObjectname As String, addChk As Boolean

    Set ws = Workbooks("nursery.xls").Worksheets("Seeding")
     Application.ScreenUpdating = False

     ckbox = Lower
     ' add a checkbox for printing
     For Each cell In ws.Range("g" & Lower & ":g" & Upper)

     myObjectname = "ckboxPrintLabels" & ckbox
     addChk = True

     For Each ctrl In ActiveSheet.CheckBoxes
     ' nasty hack to overcome the limitations of vba in excel - no eval!
        If ctrl.name = myObjectname Then
        addChk = False ' if chkbox already exists
      ctrl.Visible = True 'switch to visible, as it may not be
      End If
       Next

    If addChk Then
    With ws.CheckBoxes.Add(cell.Left, _
     cell.Top, cell.Width, cell.Height)
     .LinkedCell = cell
     .Interior.ColorIndex = xlNone
     .Caption = ""
     .name = myObjectname
     .Visible = True
    End With
    End If
    ckbox = ckbox + 1
    Next
    Application.ScreenUpdating = True
    End Sub

고마워, 당신 말이 맞아 창조가 문제입니다. 좋은 코드를 추가하기 위해 메인 포스트를 수정했습니다.
— 오닉스

빠른 답변을 응원하고 수락
— brettdj
당사 사이트를 사용함과 동시에 당사의 쿠키 정책과 개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.