CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Threaded View

  1. #1
    Join Date
    Sep 2009
    Posts
    4

    Loop not catching all values

    'SHEETS
    For Each ctrl As Control In Me.Controls
    What am I doing wrong here? When I put in manual text after the line return it fill in but as is it doesn't pick up all the checkboxes under HEADINGS. It does create all the sheets under SHEETS.

    Code:
    If (TypeOf ctrl Is CheckBox AndAlso CType(ctrl, CheckBox).Checked) AndAlso CType(ctrl, CheckBox).Name.Contains("Sheet") Then
                    wb.Worksheets("Template").copy(after:=sheet)
                    sheet = wb.ActiveSheet
                    sheet.Name = CType(ctrl, CheckBox).Text
                    
                    'HEADINGS  *******ONLY CATCHING 1ST HEADING ON EACH SHEET*******
                    For Each head As Control In Me.Controls
                        If (TypeOf head Is CheckBox AndAlso CType(head, CheckBox).Checked) AndAlso CType(head, CheckBox).Name.Contains("Head" & sheet.Name) Then
                            sheet.Range("E31").Select()
                            excel.ActiveCell.Value2 = CType(head, CheckBox).Text
                            'LINE RETURN
                            excel.ActiveCell.Offset(+1, 0).Select()
                        End If
                    Next
                End If
            Next
    Last edited by HanneSThEGreaT; September 19th, 2009 at 04:14 AM. Reason: Code Tags!

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured