Consulting

Results 1 to 4 of 4

Thread: Using form control checkboxes to clear ranges on other pages- VBA Excel

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #3
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,970
    try changing:
    If CheckBox.Value = False Then
    to:
    If CheckBox.Value = xlOff Then

    You could also reduce your looping a bit:
    Sub CommandButton1_Click()
    Dim ws As Worksheet, CheckBox, c
    
    For Each CheckBox In CheckBoxes
      If CheckBox = xlOff Then
        Set ws = Nothing
        On Error Resume Next
        Set ws = Sheets(CheckBox.Caption)
        On Error GoTo 0
        If Not ws Is Nothing Then
          For c = 1 To ws.Cells(Rows.Count, 8).End(xlUp).Offset(1, 0).Row    'if not checked, looks on current worksheet (within loop) and if any "Y" or "y" vals, clears them
            If Application.Trim(UCase(ws.Range("H" & c).Value)) = "Y" Then ws.Range("H" & c).ClearContents 'caters for upper and lower case and leading/trailing spaces.
          Next
        End If
      End If
    Next CheckBox
    End Sub
    Last edited by p45cal; 09-07-2018 at 08:43 AM.
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •