Results 1 to 4 of 4

Loop through rows (Dynamic number)

Threaded View

  1. #1
    Forum Contributor
    Join Date
    06-06-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    180

    Loop through rows (Dynamic number)

    Hi All,

    I have created the code below (Spreadsheet Attached) which works for the first row but I want the code to loop through each row. I know there is a way aroud this by using count and then the rows will increment by 1 every time it loops through the code. Unfortunately I do not know how to do this.

    P.s. i do not want to specify how many rows and the number of rows is dynamic.

    Any ideas? Any help would be greatly appreciated.

    Option Explicit
    Sub RuleTesting()
    
    Dim QRule As String
    Dim RTRule As String
    Dim CurrentResult As Integer
    Dim Red As String
    Dim Amber As String
    Dim Green As String
    Dim Status As Range
    Dim RedNo As String
    Dim GreenNo As String
    Dim Symbol As String
    
    Set Status = ThisWorkbook.Sheets("Results_Q").Range("F2")
    
    ' Variables
    QRule = ThisWorkbook.Sheets("Results_Q").Range("E2").Value
    RTRule = ThisWorkbook.Sheets("RuleTable_RT").Range("A2").Value
    CurrentResult = ThisWorkbook.Sheets("Results_Q").Range("D2").Value
    RedNo = ThisWorkbook.Sheets("RuleTable_RT").Range("C2").Value
    GreenNo = ThisWorkbook.Sheets("RuleTable_RT").Range("G2").Value
    Symbol = ThisWorkbook.Sheets("RuleTable_RT").Range("B2").Value
    
    
    ' Selects first 'Status' cell & Loop Through rows
    ThisWorkbook.Sheets("Results_Q").Range("F2").Select
    Do Until ActiveCell.Offset(1, -1) = ""
    ActiveCell.Offset(1, 0).Select
    ' Calculate the RAG
    If Symbol = ">" Then
    
    If CurrentResult > RedNo Then
    Status = "Red"
    ElseIf CurrentResult < GreenNo Then Status = "Green"
    ElseIf Symbol = ">" Then Status = "Amber"
    
    ElseIf Symbol = "<" Then
    
    If CurrentResult < RedNo Then
    Status = "Red"
    ElseIf CurrentResult > GreenNo Then Status = "Green"
    Else: Status = "Amber"
    
    
    
    End If
    End If
    End If
    Loop
    End Sub
    Kind regards,

    James Elwell
    Attached Files Attached Files
    Last edited by forrestgump1980; 12-18-2014 at 12:02 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. How to loop through dynamic ranges using columns rather than rows
    By xcelnovice101 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 06-24-2014, 06:28 PM
  2. [SOLVED] Macro to loop through dynamic number of rows checking adjacent for certain criteria
    By ellismith in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-13-2014, 04:12 PM
  3. [SOLVED] Rename Sheets by using Dynamic Loop for the rows
    By desolatori in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-30-2014, 09:36 AM
  4. Do-While loop within a do-while loop? Dealing with changing number of rows
    By Motox in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-02-2012, 12:59 AM
  5. Dynamic Columns and Rows Selecting all Loop
    By excel0831 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-22-2012, 05:41 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