+ Reply to Thread
Results 1 to 4 of 4

Variable sheets, variable input

Hybrid View

  1. #1
    Registered User
    Join Date
    03-23-2009
    Location
    Provo, UT
    MS-Off Ver
    Excel 2003
    Posts
    11

    Variable sheets, variable input

    I run a machine that scans parts and is able to output the scans into Excel. Each part scanned creates a new sheet, and the number of sheets is variable as the number of parts scanned depends on the size of the lot. Also, since each part scanned is going to have a different number of features, the information being output on each sheet will be variable as well. I am trying to figure out how to write a macro that will find the first feature, find the values for that feature I am looking for, output a max and min into a final sheet, and repeat for each feature, and for each sheet. I hope this is clear. Any help would be greatly appreciated. Thanks.
    Last edited by Beowulfdl; 03-30-2009 at 08:39 PM.

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,450

    Re: Variable sheets, variable input

    It would help if you could post example with a few sheets and the summary page. With details of the cells to checked and the expected result.
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    03-23-2009
    Location
    Provo, UT
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Variable sheets, variable input

    Thanks for the reply. Here is an example with two parts scanned and a Final Sheet with the wanted results. I added notes on the Final Sheet page to be clear. Hopefully it makes sense.
    Attached Files Attached Files

  4. #4
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,450

    Re: Variable sheets, variable input

    Here a first stab at it. Doesn't do anything with OUTTOL information though.

    Sub Summary()
    
        Dim shtSummary As Worksheet
        Dim shtData As Worksheet
        Dim lngNRows As Long
        Dim vntCol As Variant
        Dim lngRow As Long
        
        With ActiveWorkbook
            .Worksheets(.Worksheets.Count).Copy after:=.Worksheets(.Worksheets.Count)
            Set shtSummary = .Worksheets(.Worksheets.Count)
            Intersect(shtSummary.UsedRange, shtSummary.Range("F:V")).Clear
            Intersect(shtSummary.UsedRange, shtSummary.Range("D:D")).Delete
        End With
        lngNRows = shtSummary.UsedRange.Rows.Count
        
        With ActiveWorkbook.Worksheets(1)
            .Columns(7).Copy shtSummary.Cells(1, 5)
            .Columns(8).Copy shtSummary.Cells(1, 6)
            .Columns(8).Copy shtSummary.Cells(1, 7)
            .Columns(12).Copy shtSummary.Cells(1, 8)
            .Columns(12).Copy shtSummary.Cells(1, 9)
            .Columns(13).Copy shtSummary.Cells(1, 10)
        End With
        
        For lngRow = 1 To shtSummary.UsedRange.Rows.Count
            If shtSummary.Cells(lngRow, 3) = "DESCRIPTION" Then
                shtSummary.Range(shtSummary.Cells(lngRow, 4), shtSummary.Cells(lngRow, 10)) = Array("AXIS", "NOMINAL", "MIN", "MAX", "DEV MIN", "DEV MAX", "OUTTOL")
            End If
        Next
        
        For Each shtData In ActiveWorkbook.Worksheets
            If shtData.Name <> shtSummary.Name Then
                For lngRow = 1 To lngNRows
                    If shtData.Cells(lngRow, 5) <> "AXIS" Then
                        'MIN
                        If shtData.Cells(lngRow, 8).Value < shtSummary.Cells(lngRow, 6).Value Then
                            shtSummary.Cells(lngRow, 6).Value = shtData.Cells(lngRow, 8).Value
                        End If
                        'MAX
                        If shtData.Cells(lngRow, 8).Value > shtSummary.Cells(lngRow, 7).Value Then
                            shtSummary.Cells(lngRow, 7).Value = shtData.Cells(lngRow, 8).Value
                        End If
                        'DEV MIN
                        If shtData.Cells(lngRow, 12).Value < shtSummary.Cells(lngRow, 8).Value Then
                            shtSummary.Cells(lngRow, 8).Value = shtData.Cells(lngRow, 12).Value
                        End If
                        'DEV MAX
                        If shtData.Cells(lngRow, 12).Value > shtSummary.Cells(lngRow, 9).Value Then
                            shtSummary.Cells(lngRow, 9).Value = shtData.Cells(lngRow, 12).Value
                        End If
                    End If
                Next
            End If
        Next
        
    End Sub

+ 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