+ Reply to Thread
Results 1 to 4 of 4

Conditional Output Loop testing values in one column & outputting in another

Hybrid View

  1. #1
    Registered User
    Join Date
    06-09-2014
    Posts
    39

    Conditional Output Loop testing values in one column & outputting in another

    Hi,

    I have a column of numerical data in column H. I want to run a loop to test the value of the data in each row of the column.

    For each cell, depending on the value, want output in column I of either "L", "M" or "H" (without the quotations). This is what I have rigged up so far, but I am doing something wrong with the offset function. Also if anyone has a suggestion for an easier way that would be cool too. Thanks

    
        Sheets("Annual Summary").Activate
        
        Dim APIrng As Range
        Set APIrng = Workbooks("Co-op Compiler.xlsm").Worksheets("Annual Summary").Range("G2:G" & lrow)
        
            For Each Cell In APIrng
                If Cell.Value > 31.1 Then
                    Offset.Cell(0, 2) = "L"
                ElseIf Cell.Value < 31.1 And Cell.Value > 22.3 Then
                    Offset.Cell(0, 2) = "M"
                ElseIf Cell.Value < 22.3 And Cell.Value > 0 Then
                    Offset.Cell(0, 2) = "H"
                End If
            Next

  2. #2
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Conditional Output Loop testing values in one column & outputting in another

    Maybe:

    Sub bakeraj256zz()
            For Each cell In APIrng
                If cell.Value > 31.1 Then
                    Cells(cell.Row, "I") = "L"
                ElseIf cell.Value < 31.1 And cell.Value > 22.3 Then
                    Cells(cell.Row, "I") = "M"
                ElseIf cell.Value < 22.3 And cell.Value > 0 Then
                    Cells(cell.Row, "I") = "H"
                End If
            Next
    End Sub
    Or

    Sub bakeraj256()
    Dim rcell As Range
    For Each rcell In Range("H2:H" & Range("H" & Rows.count).End(3)(1).Row)
        Select Case rcell.Value
            Case Is > 31.1
                Cells(rcell.Row, "I") = "L"
            Case Is < 22.3
                Cells(rcell.Row, "I") = "H"
            Case Is > 22.3, Is < 31.1
                Cells(rcell.Row, "I") = "M"
        End Select
    Next rcell
    End Sub

  3. #3
    Registered User
    Join Date
    06-09-2014
    Posts
    39

    Re: Conditional Output Loop testing values in one column & outputting in another

    Excellent, this worked. Thank you so much. I used the first method.

  4. #4
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Conditional Output Loop testing values in one column & outputting in another

    You're welcome. Glad to help out and thanks for the feedback.

+ 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. Replies: 3
    Last Post: 10-16-2013, 02:20 PM
  2. loop through rows and output calculated values on new sheet
    By leejc in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-03-2011, 07:01 PM
  3. Need macro to loop through input cell values and copy output value
    By jaf in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-27-2011, 02:59 PM
  4. Outputting values in column B that correspond to certain values in column A
    By alvine in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-23-2010, 10:05 AM
  5. Using loop to output compounded values
    By derekbrown in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-13-2007, 06:06 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