Results 1 to 10 of 10

Loop through columns then next row with unit convert

Threaded View

  1. #1
    Registered User
    Join Date
    09-13-2012
    Location
    Maine
    MS-Off Ver
    Excel 2010
    Posts
    45

    Loop through columns then next row with unit convert

    All of my attempts to simplify this lop have failed an every change I have to make to the if statement has to be made over and over for all lines. Starting at the second row it is supposed to check to make sure the cell in column 5 of the current row is greater than zero to start reading through the rows. Then to check the value in the top cell of the current column and if its value matches one of the two values listed in the if then statements. Values range from -2.11 to 2.1. If the statement is satisfied then the corresponding value of the row and column would be converted from meters to inches and written to the new sheet "Upchain Edit" in the column with the corresponding column header value instead of equaling line = line +BLAHBLAH.

    Example new sheet header layout:
    Excel.JPG

    With WS
        LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
        LastCol = .Cells(1, .Columns.Count).End(xlToLeft).Column
        i = 0
        MaxVal = WWorksheetFunction.Max(Range(.Cells(2, 8), .Cells(LastRow, LastCol)))
        MaxVal = (WorksheetFunction.Convert((MaxVal), "m", "in"))
            For A = 2 To LastRow 'label rows as A, A=1 at row 2
            If .Cells(A, 5) > 0 Then
                    i = i + 1
                    CurSta = StartStation + (Direction * i)
      '--------------------------------------------------------------------------------------
      '--------------------------------------------------------------------------------------
      '-------The below for loop populates the string containing the 37 laser readings-------
      '----------------for a 12 foot wide bar centered around the zero laser-----------------
      '--------------------------------------------------------------------------------------
      '--------------------------------------------------------------------------------------
                For B = 8 To LastCol 'label columns as B, B=1 at column H
                    'Enter 39 laser readings to string at 1/10th of a meter spacing (about 4in)
                    
                    If (.Cells(2, B) <> "") And (.Cells(1, B).Value = -2.11) Or (.Cells(1, B).Value = -2.1) Then
                        Line = Line + WorksheetFunction.Convert((.Cells(A, B)), "m", "in")
                    End If
                    If (.Cells(2, B) <> "") And (.Cells(1, B).Value = -2.01) Or (.Cells(1, B).Value = -2#) Then
                        Line = Line + WorksheetFunction.Convert((.Cells(A, B)), "m", "in")
                    End If
                    If (.Cells(2, B) <> "") And (.Cells(1, B).Value = -1.91) Or (.Cells(1, B).Value = -1.9) Then
                        Line = Line + WorksheetFunction.Convert((.Cells(A, B)), "m", "in")
                    End If
                    If (.Cells(2, B) <> "") And (.Cells(1, B).Value = -1.81) Or (.Cells(1, B).Value = -1.8) Then
                        Line = Line + WorksheetFunction.Convert((.Cells(A, B)), "m", "in")
                    End If
                    If (.Cells(2, B) <> "") And (.Cells(1, B).Value = -1.71) Or (.Cells(1, B).Value = -1.7) Then
                        Line = Line + WorksheetFunction.Convert((.Cells(A, B)), "m", "in")
                    End If
                    If (.Cells(2, B) <> "") And (.Cells(1, B).Value = -1.61) Or (.Cells(1, B).Value = -1.6) Then
                        Line = Line + WorksheetFunction.Convert((.Cells(A, B)), "m", "in")
                    End If
                    If (.Cells(2, B) <> "") And (.Cells(1, B).Value = -1.51) Or (.Cells(1, B).Value = -1.5) Then
                        Line = Line + WorksheetFunction.Convert((.Cells(A, B)), "m", "in")
                    End If
                    If (.Cells(2, B) <> "") And (.Cells(1, B).Value = -1.41) Or (.Cells(1, B).Value = -1.4) Then
                        Line = Line + WorksheetFunction.Convert((.Cells(A, B)), "m", "in")
                    End If
                    If (.Cells(2, B) <> "") And (.Cells(1, B).Value = -1.31) Or (.Cells(1, B).Value = -1.3) Then
                        Line = Line + WorksheetFunction.Convert((.Cells(A, B)), "m", "in")
                    End If
                    If (.Cells(2, B) <> "") And (.Cells(1, B).Value = -1.21) Or (.Cells(1, B).Value = -1.2) Then
                        Line = Line + WorksheetFunction.Convert((.Cells(A, B)), "m", "in")
                    End If
                    If (.Cells(2, B) <> "") And (.Cells(1, B).Value = -1.11) Or (.Cells(1, B).Value = -1.1) Then
                        Line = Line + WorksheetFunction.Convert((.Cells(A, B)), "m", "in")
                    End If
                    If (.Cells(2, B) <> "") And (.Cells(1, B).Value = -1.01) Or (.Cells(1, B).Value = -1#) Then
                        Line = Line + WorksheetFunction.Convert((.Cells(A, B)), "m", "in")
                    End If
                    If (.Cells(2, B) <> "") And (.Cells(1, B).Value = -0.91) Or (.Cells(1, B).Value = -0.9) Then
                        Line = Line + WorksheetFunction.Convert((.Cells(A, B)), "m", "in")
                    End If
                    If (.Cells(2, B) <> "") And (.Cells(1, B).Value = -0.81) Or (.Cells(1, B).Value = -0.8) Then
                        Line = Line + WorksheetFunction.Convert((.Cells(A, B)), "m", "in")
                    End If
                    If (.Cells(2, B) <> "") And (.Cells(1, B).Value = -0.71) Or (.Cells(1, B).Value = -0.7) Then
                        Line = Line + WorksheetFunction.Convert((.Cells(A, B)), "m", "in")
                    End If
                    If (.Cells(2, B) <> "") And (.Cells(1, B).Value = -0.61) Or (.Cells(1, B).Value = -0.6) Then
                        Line = Line + WorksheetFunction.Convert((.Cells(A, B)), "m", "in")
                    End If
                    If (.Cells(2, B) <> "") And (.Cells(1, B).Value = -0.51) Or (.Cells(1, B).Value = -0.5) Then
                        Line = Line + WorksheetFunction.Convert((.Cells(A, B)), "m", "in")
                    End If
                    If (.Cells(2, B) <> "") And (.Cells(1, B).Value = -0.41) Or (.Cells(1, B).Value = -0.4) Then
                        Line = Line + WorksheetFunction.Convert((.Cells(A, B)), "m", "in")
                    End If
                    If (.Cells(2, B) <> "") And (.Cells(1, B).Value = -0.31) Or (.Cells(1, B).Value = -0.3) Then
                        Line = Line + WorksheetFunction.Convert((.Cells(A, B)), "m", "in")
                    End If
                    If (.Cells(2, B) <> "") And (.Cells(1, B).Value = -0.21) Or (.Cells(1, B).Value = -0.2) Then
                        Line = Line + WorksheetFunction.Convert((.Cells(A, B)), "m", "in")
                    End If
                    If (.Cells(2, B) <> "") And (.Cells(1, B).Value = -0.11) Or (.Cells(1, B).Value = -0.1) Then
                        Line = Line + WorksheetFunction.Convert((.Cells(A, B)), "m", "in")
                    End If
                    If (.Cells(2, B) <> "") And (.Cells(1, B).Value = -0.01) Or (.Cells(1, B).Value = -0#) Then
                        Line = Line + WorksheetFunction.Convert((.Cells(A, B)), "m", "in")
                    End If
                    If (.Cells(2, B) <> "") And (.Cells(1, B).Value = 0.09) Or (.Cells(1, B).Value = 0.1) Then
                        Line = Line + WorksheetFunction.Convert((.Cells(A, B)), "m", "in")
                    End If
                    If (.Cells(2, B) <> "") And (.Cells(1, B).Value = 0.19) Or (.Cells(1, B).Value = 0.2) Then
                        Line = Line + WorksheetFunction.Convert((.Cells(A, B)), "m", "in")
                    End If
                    If (.Cells(2, B) <> "") And (.Cells(1, B).Value = 0.29) Or (.Cells(1, B).Value = 0.3) Then
                        Line = Line + WorksheetFunction.Convert((.Cells(A, B)), "m", "in")
                    End If
                    If (.Cells(2, B) <> "") And (.Cells(1, B).Value = 0.39) Or (.Cells(1, B).Value = 0.4) Then
                        Line = Line + WorksheetFunction.Convert((.Cells(A, B)), "m", "in")
                    End If
                    If (.Cells(2, B) <> "") And (.Cells(1, B).Value = 0.49) Or (.Cells(1, B).Value = 0.5) Then
                        Line = Line + WorksheetFunction.Convert((.Cells(A, B)), "m", "in")
                    End If
                    If (.Cells(2, B) <> "") And (.Cells(1, B).Value = 0.59) Or (.Cells(1, B).Value = 0.6) Then
                        Line = Line + WorksheetFunction.Convert((.Cells(A, B)), "m", "in")
                    End If
                    If (.Cells(2, B) <> "") And (.Cells(1, B).Value = 0.69) Or (.Cells(1, B).Value = 0.7) Then
                        Line = Line + WorksheetFunction.Convert((.Cells(A, B)), "m", "in")
                    End If
                    If (.Cells(2, B) <> "") And (.Cells(1, B).Value = 0.79) Or (.Cells(1, B).Value = 0.8) Then
                        Line = Line + WorksheetFunction.Convert((.Cells(A, B)), "m", "in")
                    End If
                    If (.Cells(2, B) <> "") And (.Cells(1, B).Value = 0.89) Or (.Cells(1, B).Value = 0.9) Then
                        Line = Line + WorksheetFunction.Convert((.Cells(A, B)), "m", "in")
                    End If
                    If (.Cells(2, B) <> "") And (.Cells(1, B).Value = 0.99) Or (.Cells(1, B).Value = 1) Then
                        Line = Line + WorksheetFunction.Convert((.Cells(A, B)), "m", "in")
                    End If
                    If (.Cells(2, B) <> "") And (.Cells(1, B).Value = 1.09) Or (.Cells(1, B).Value = 1.1) Then
                        Line = Line + WorksheetFunction.Convert((.Cells(A, B)), "m", "in")
                    End If
                    If (.Cells(2, B) <> "") And (.Cells(1, B).Value = 1.19) Or (.Cells(1, B).Value = 1.2) Then
                        Line = Line + WorksheetFunction.Convert((.Cells(A, B)), "m", "in")
                    End If
                    If (.Cells(2, B) <> "") And (.Cells(1, B).Value = 1.29) Or (.Cells(1, B).Value = 1.3) Then
                        Line = Line + WorksheetFunction.Convert((.Cells(A, B)), "m", "in")
                    End If
                    If (.Cells(2, B) <> "") And (.Cells(1, B).Value = 1.39) Or (.Cells(1, B).Value = 1.4) Then
                        Line = Line + WorksheetFunction.Convert((.Cells(A, B)), "m", "in")
                    End If
                    If (.Cells(2, B) <> "") And (.Cells(1, B).Value = 1.49) Or (.Cells(1, B).Value = 1.5) Then
                        Line = Line + WorksheetFunction.Convert((.Cells(A, B)), "m", "in")
                    End If
                    If (.Cells(2, B) <> "") And (.Cells(1, B).Value = 1.59) Or (.Cells(1, B).Value = 1.6) Then
                        Line = Line + WorksheetFunction.Convert((.Cells(A, B)), "m", "in")
                    End If
                    If (.Cells(2, B) <> "") And (.Cells(1, B).Value = 1.69) Or (.Cells(1, B).Value = 1.7) Then
                        Line = Line + WorksheetFunction.Convert((.Cells(A, B)), "m", "in")
                    End If
                    If (.Cells(2, B) <> "") And (.Cells(1, B).Value = 1.79) Or (.Cells(1, B).Value = 1.8) Then
                        Line = Line + WorksheetFunction.Convert((.Cells(A, B)), "m", "in")
                    End If
                    If (.Cells(2, B) <> "") And (.Cells(1, B).Value = 1.89) Or (.Cells(1, B).Value = 1.9) Then
                        Line = Line + WorksheetFunction.Convert((.Cells(A, B)), "m", "in")
                    End If
                    If (.Cells(2, B) <> "") And (.Cells(1, B).Value = 1.99) Or (.Cells(1, B).Value = 2#) Then
                        Line = Line + WorksheetFunction.Convert((.Cells(A, B)), "m", "in")
                    End If
                    If (.Cells(2, B) <> "") And (.Cells(1, B).Value = 2.09) Or (.Cells(1, B).Value = 2.1) Then
                        Line = Line + WorksheetFunction.Convert((.Cells(A, B)), "m", "in")
                    End If
                Next
                Line = "" 'Clears the Line variable to begin the next iteration
                A = A + 150 '150 skips rows to get down to next 50ft increment
            End If
        Next
    End With
    Attached Files Attached Files
    Last edited by cnash52; 03-03-2016 at 11:34 AM. Reason: Added example csv to be edited

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 4
    Last Post: 10-07-2015, 06:04 AM
  2. Loop Across Columns...If Blank Cell, Loop Down Rows
    By flindy87 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-25-2014, 07:05 PM
  3. Loop Across Columns If Blank Cell Loop Down Rows
    By flindy87 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-05-2014, 10:22 AM
  4. [SOLVED] Unit increase relative to variable unit thresholds
    By Fr3dle in forum Excel General
    Replies: 6
    Last Post: 07-01-2013, 06:57 AM
  5. Replies: 4
    Last Post: 06-07-2013, 02:01 PM
  6. [SOLVED] Use VBA to run "text to columns' Loop on first row to convert from text to date format
    By csmiley in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 06-03-2013, 02:06 PM
  7. convert unit change to percentile rank change
    By dujang in forum Excel General
    Replies: 1
    Last Post: 11-15-2006, 02:53 PM

Tags for this Thread

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