+ Reply to Thread
Results 1 to 7 of 7

Uncheck Checkbox on ThisWorkbook > On All Sheets

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    08-28-2012
    Location
    Klang, Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    113

    Uncheck Checkbox on ThisWorkbook > On All Sheets

    Hi All!
    Having a lil problem on my code. For the current code i used now, it worked only on Sheet1 but not sheet2,3,4.....

    Sub UncheckAll()
        Dim ChkBox As Excel.CheckBox
              
          For Each ChkBox In ActiveSheet.CheckBoxes
            ChkBox.Value = xlOff
          Next ChkBox
          NextScreening
    End Sub
    What should i change in order for excel to uncheck all of the checkbox on every sheets with checkbox in?

    BRgds
    C.Y.Chua

  2. #2
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    8,027

    Re: Uncheck Checkbox on ThisWorkbook > On All Sheets

    Try:

    Sub UncheckAll()
        Dim ws As Worksheet
        Dim ChkBox As Excel.CheckBox
        For Each ws In Sheets
            With ws
                For Each ChkBox In .CheckBoxes
                    ChkBox.Value = xlOff
                Next ChkBox
            Next ws
        End With
        NextScreening
    End Sub

  3. #3
    Forum Contributor
    Join Date
    08-28-2012
    Location
    Klang, Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    113

    Re: Uncheck Checkbox on ThisWorkbook > On All Sheets

    Hi Mumps1
    Thanks for your reply. I had try the code below your show me.
    It shown error msg : Next Without For.

    It might be other code is wrong or something. Below is my code in 1 module. Sorry to tell you that i am noob for VB.

    Sub SaveScreeningWithNewName()
        Dim NewFN As Variant
        ' Copy Screening to a new workbook
        Sheets(Array("Agent-Sea", "Agent-Air", "B.Confirmation", "S.I.", "HBL", "Agent Quotation")).Copy
        ActiveSheet.Shapes.Range(Array("Save&Clear")).Delete
        NewFN = "\\CYCHUA-PC\Users\Public\Documents\Agent Bill\" & Sheets(1).Range("c2").Value & Sheets(1).Range("D2").Text & " " & Sheets(1).Range("I1").Text & " " & Sheets(1).Range("j2").Text & " " & Sheets(1).Range("k2").Text & ".xlsx"
        ActiveWorkbook.SaveAs NewFN, FileFormat:=xlOpenXMLWorkbook
        ActiveWorkbook.Close
        UncheckAll
    End Sub
    Sub UncheckAll()
        Dim ws As Worksheet
        Dim ChkBox As Excel.CheckBox
        For Each ws In Sheets
            With ws
                For Each ChkBox In .CheckBoxes
                    ChkBox.Value = xlOff
                Next ChkBox
            Next ws
        End With
        NextScreening
    End Sub
    Sub NextScreening()
        Sheets("Agent-Sea").Range("C2").Value = Range("C2").Value + 1
        Range("I1:L2").ClearContents
        Range("C4").ClearContents
        Range("B5:L14").ClearContents
        Range("d18:l18").ClearContents
        Range("d20:G28").ClearContents
        Range("d30:G37").ClearContents
    End Sub
    Other than this uncheck thingy. I face another problem, when i copy the command button from Sheet1 to Sheet2, i thought it would work but it dont....

  4. #4
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    8,027

    Re: Uncheck Checkbox on ThisWorkbook > On All Sheets

    My apologies. I got a couple of lines reversed. Try this:

    Sub UncheckAll()
        Dim ws As Worksheet
        Dim ChkBox As Excel.CheckBox
        For Each ws In Sheets
            With ws
                For Each ChkBox In .CheckBoxes
                    ChkBox.Value = xlOff
                Next ChkBox
            End With
        Next ws
        NextScreening
    End Sub

  5. #5
    Forum Contributor
    Join Date
    08-28-2012
    Location
    Klang, Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    113

    Re: Uncheck Checkbox on ThisWorkbook > On All Sheets

    It works brilliantly now.

    Sorry to ask for additional stuff, Mumps1.

    On Sheet1 my command button work well. When i copy and paste the command button from sheet1 to sheet2. It showed error msg "cannot change part of a merged cell".

    As i seen the command button, is based on the sheet2 for the function code of clearing contents. intead of sheet1 which as below,
    Sub NextScreening()
        Sheets("Agent-Sea").Range("C2").Value = Range("C2").Value + 1
        Range("I1:L2").ClearContents
        Range("C4").ClearContents
        Range("B5:L14").ClearContents
        Range("d18:l18").ClearContents
        Range("d20:G28").ClearContents
    How should i correct this?

  6. #6
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    8,027

    Re: Uncheck Checkbox on ThisWorkbook > On All Sheets

    It looks like you are trying to clear the contents of cells which are merged. Merged cells most often cause problems in Excel and you should try to avoid them if you can. Try changing the line
    Range("d20:G28").ClearContents
    to
    Range("d20:G28").MergeArea.ClearContents

  7. #7
    Forum Contributor
    Join Date
    08-28-2012
    Location
    Klang, Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    113

    Re: Uncheck Checkbox on ThisWorkbook > On All Sheets

    Actually i doing it correctly as i feel. Just that the clearing contents code is Sheet1, but when i click the command button on sheet2, it referred to sheet2 cell which is merged.
    Last edited by cychua; 01-24-2013 at 05:34 AM. Reason: Do have my company logo on file

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1