+ Reply to Thread
Results 1 to 15 of 15

importing results from a checkbox

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    10-04-2010
    Location
    London
    MS-Off Ver
    Office 365
    Posts
    469

    importing results from a checkbox

    I'm working with a macro to import specific cell data from many single standardised excel files into a master file.

    Problem im having is with these single files contain "Yes" or "No" checkboxes and i require the answer (either yes or no) to pull through into the master file.

    Is this possible as the checkboxes aren't physically in the cell, is there perhaps a simpler way im missing?

    inserted current code below (only relevant sections included)

    
    With Application.FileDialog(msoFileDialogFolderPicker) ' Select folder where project files are saved
        .ButtonName = "OK"
        .Title = "Select folder containing files to consolidate"
        .AllowMultiSelect = False
        .Show
        On Error Resume Next
        Path = .SelectedItems(1)
        Err.Clear
        On Error GoTo 0
    End With
    If Path = Empty Then MsgBox "Macro cancelled.": Exit Sub       ' If message box is cancelled exit macro
    
    If Right(Path, 1) <> "\" Then Path = Path & "\"
    
    FileName = Dir(Path & "*.xlsx")
    Do While FileName <> ""
        Workbooks.Open FileName:=Path & FileName, ReadOnly:=True
        For Each Sh In ActiveWorkbook.Worksheets
        If Sh.Range("A5").Value = "Project" Then               'If cell A5 contains the text "Project" then copy data from that sheet
            MyArray(0) = Sh.Range("B4").Value       
            MyArray(1) = Sh.Range("B5").Value      
            MyArray(2) = Sh.Range("B6").Value      
            MyArray(3) = Sh.Range("B7").Value       
            MyArray(4) = Sh.Range("B8").Value       
            MyArray(5) = Sh.Range("B9").Value     
            MyArray(6) = Sh.Range("B10").Value     
            MyArray(7) = Sh.Range("B11").Value      
            MyArray(8) = Sh.Range("B12").Value    
            MyArray(9) = Sh.Range("B13").Value      
            MyArray(10) = Sh.Range("B14").Value     
            MyArray(11) = Sh.Range("B15").Value     
            MyArray(12) = Sh.Range("B16").Value    
            MyArray(13) = Sh.Range("B17").Value     
            MyArray(14) = Sh.Range("B22").Value     
            MyArray(15) = Sh.Range("B24").Value    
            MyArray(16) = Sh.Range("B25").Value     
            MyArray(17) = Sh.Range("B26").Value     
            MyArray(18) = Sh.Range("B27").Value     
            MyArray(19) = Sh.Range("B28").Value     
            MyArray(20) = Sh.Range("B29").Value    
            MyArray(21) = Sh.Range("B30").Value     
            MyArray(22) = Sh.Range("B31").Value    ' checkbox 1
            MyArray(23) = Sh.Range("B32").Value    ' checkbox 2
            MyArray(24) = Sh.Range("B33").Value    ' checkbox 3
            MyArray(25) = Sh.Range("B35").Value     
            MyArray(26) = Sh.Range("B36").Value  
            MyArray(27) = Sh.Range("B37").Value   
            MyArray(28) = Sh.Range("B39").Value    
            MyArray(29) = Sh.Range("B40").Value   
                         
            LR = ThisWorkbook.Sheets(MainSh).Range("A" & Rows.Count).End(xlUp).Row + 1 ' calculate the last row of the data range
            For i = 0 To 29     ' Number of columns in the range
                ThisWorkbook.Sheets(MainSh).Cells(LR, i + 1).Value = MyArray(i)
            Next i
            
        ThisWorkbook.Sheets(MainSh).Hyperlinks.Add _
        Anchor:=ThisWorkbook.Sheets(MainSh).Range("A" & LR), Address:=Path & FileName    ' Add hyperlinks to column A to link to project files
    
        End If
        Next Sh
        ActiveWorkbook.Close False
        FileName = Dir()
    Loop
    
    
    End Sub
    Last edited by Gti182; 02-28-2014 at 12:03 PM.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: importing results from a checkbox

    Are the checkboxes linked to cells?
    If posting code please use code tags, see here.

  3. #3
    Forum Contributor
    Join Date
    10-04-2010
    Location
    London
    MS-Off Ver
    Office 365
    Posts
    469

    Re: importing results from a checkbox

    they are not linked no. they are simple form control checkboxes

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: importing results from a checkbox

    You'll need to use the Shapes collection of the worksheet(s) to get the values if the checkbox(es).

    PS Forms chevkboxes can have linked cells.

  5. #5
    Forum Contributor
    Join Date
    10-04-2010
    Location
    London
    MS-Off Ver
    Office 365
    Posts
    469

    Re: importing results from a checkbox

    that sounds interesting Norie, can you elaborate a bit more not following 100%

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: importing results from a checkbox

    This will loop through all the shapes on Sheet1, if they are checkboxes it will output their value - 1 for checked and -4146 for unchecked.
    For Each chk In Sheets("Sheet1").Shapes
    
        If TypeName(chk.OLEFormat.Object) = "CheckBox" Then
            MsgBox chk.OLEFormat.Object.Value
        End If
    
    Next chk

  7. #7
    Forum Contributor
    Join Date
    10-04-2010
    Location
    London
    MS-Off Ver
    Office 365
    Posts
    469

    Re: importing results from a checkbox

    thats awesome! Ok i see how it works now but a bit unsure on how to incorporate it into my code, any tips?

  8. #8
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: importing results from a checkbox

    I don't really know too much about the sheets you are dealing with but if you always want the values from specific checkboxes you coudl use there names.
    MyArray(22) = Iif(Sh.Shapes("CheckBox 1").OLEFormat.Object.Value = 1, "Yes", "No")    ' checkbox 1

  9. #9
    Forum Contributor
    Join Date
    10-04-2010
    Location
    London
    MS-Off Ver
    Office 365
    Posts
    469

    Re: importing results from a checkbox

    ok i follow that, inserted the above code but getting a runtime error -2147024809 (80070057) the item with the specified name was not found

  10. #10
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: importing results from a checkbox

    Have you checked the name?

    Is it definitely a Forms checkbox?

    Can you upload an example workbook?

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

  11. #11
    Forum Contributor
    Join Date
    10-04-2010
    Location
    London
    MS-Off Ver
    Office 365
    Posts
    469

    Re: importing results from a checkbox

    template file attached.

    not sure how to check the checkbox name
    Attached Files Attached Files

  12. #12
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: importing results from a checkbox

    Select the checkbox and it's name will appear in the name box next to the formula bar.

  13. #13
    Forum Contributor
    Join Date
    10-04-2010
    Location
    London
    MS-Off Ver
    Office 365
    Posts
    469

    Re: importing results from a checkbox

    i put a space between Check and Box works 100% now thanks so much for the help!

  14. #14
    Forum Contributor
    Join Date
    10-04-2010
    Location
    London
    MS-Off Ver
    Office 365
    Posts
    469

    Re: importing results from a checkbox

    great, see it now

  15. #15
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: importing results from a checkbox

    Glad it worked.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. VBA Excel checkbox results with If statement not correct
    By chaz1010 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-16-2014, 06:15 AM
  2. importing website results into excel
    By yijun_6 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-07-2013, 10:02 AM
  3. Importing data to Excel and assiging the macro to Checkbox
    By TallOne in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-21-2012, 11:28 AM
  4. Return a string from multiple checkbox results
    By dillinger in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-01-2010, 11:46 AM
  5. Importing checkbox data from web page
    By Linda Ellison in forum Excel General
    Replies: 0
    Last Post: 04-18-2006, 01:46 PM

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