dcsimg
Page 2 of 2 FirstFirst 12
Results 41 to 44 of 44

Thread: Combing Multiple Excel Worksheets onto One Worksheet Based on Check Box Selection

  1. #41

    Thread Starter
    Member
    Join Date
    Dec 2018
    Posts
    49

    Re: Combing Multiple Excel Worksheets onto One Worksheet Based on Check Box Selection

    Quote Originally Posted by Nish12 View Post
    Will the above code work if I have more than 5 buttons? Lets say I have 20 buttons. Do I just update "For ch = 1 To 4" to "For ch = 1 To 20"?

    When I add checkboxes they sometimes don't increment in order, could this cause an issue? I have an issue where the "With s.Shapes("Check Box " & ch)" line of code is causing a run time error '-2147024809 (80070057)': The item with the specified name wasn't found. Trying to rename the check box in the name field to the top left of excel but the update isn't sticking....it reverts back to the check box number it has.

    Open to suggestions.
    Referring to this code in my above comment:
    Dim s As Worksheet, rng As Range, dest As Worksheet
    Set dest = Sheets("Consolidated invoice")
    For ch = 1 To 4
    Set s = Sheets("intake form")
    With s.Shapes("Check Box " & ch)
    If .OLEFormat.Object.Value = 1 Then
    Set rng = Sheets(.OLEFormat.Object.Caption).UsedRange
    Set rng = rng.Offset(2).Resize(rng.Rows.Count - 2)
    rng.Copy dest.Cells(Rows.Count, 3).End(xlUp).Offset(2)
    End If
    End With
    Next

  2. #42

    Thread Starter
    Member
    Join Date
    Dec 2018
    Posts
    49

    Re: Combing Multiple Excel Worksheets onto One Worksheet Based on Check Box Selection

    My above comment is referring to the below code:

    Dim s As Worksheet, rng As Range, dest As Worksheet
    Set dest = Sheets("Consolidated invoice")
    For ch = 1 To 4
    Set s = Sheets("intake form")
    With s.Shapes("Check Box " & ch)
    If .OLEFormat.Object.Value = 1 Then
    Set rng = Sheets(.OLEFormat.Object.Caption).UsedRange
    Set rng = rng.Offset(2).Resize(rng.Rows.Count - 2)
    rng.Copy dest.Cells(Rows.Count, 3).End(xlUp).Offset(2)
    End If
    End With
    Next

  3. #43
    PowerPoster
    Join Date
    Dec 2004
    Posts
    24,433

    Re: Combing Multiple Excel Worksheets onto One Worksheet Based on Check Box Selection

    When I add checkboxes they sometimes don't increment in order, could this cause an issue?
    i do not believe it would have any problem if the caption is the same as the worksheet name, and the numbers are sequential, the order shouldn't matter, a problem would occur if any numbers are missing
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  4. #44
    PowerPoster
    Join Date
    Dec 2004
    Posts
    24,433

    Re: Combing Multiple Excel Worksheets onto One Worksheet Based on Check Box Selection

    if you are still watching this thread, it occurred to me that it might be better to loop through all the sheets, then check if the checkbox is checked, to simplify this i would add all the checkbox values to a collection with the caption as the collection index

    Code:
    Dim c As Collection, sh As Shape
    Set c = New Collection
    For Each sh In Sheets("intake form").Shapes
        If sh.Type = msoFormControl Then
            If sh.FormControlType = xlCheckBox Then
                c.Add sh.OLEFormat.Object.Value, sh.OLEFormat.Object.Caption
            End If
        End If
    Next
    For Each sht In Sheets
    If Not sht.Name = "Intake Form" And Not sht.Name = "Consolidated Invoice" Then
        If c(sht.Name) = 1 Then
            MsgBox sht.Name & "  is checked"
            ' Put all the other code here for each sheet
        End If
    End If
    Next
    using this it will not matter at all what the name of the shape containing the checkbox, only that the caption of the checkboxes match the sheet names, adding or removing checkboxes will not affect the code regardless of the order of the checkboxes, sheets will always be processed in the order of the tabs
    the code is tested to just display the sheet names that match the checkboxes that are checked
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Page 2 of 2 FirstFirst 12

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width