Results 1 to 11 of 11

Thread: How to set a loop around a script?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1

    How to set a loop around a script?

    I have made the VBA script below.
    With the script I can do every row by hand.
    But I have around 5,000 rows, so I want to try to make a loop around it or something like that.
    But I don't know how.
    Can anybody help me?
    Thank you.

    Sub SetGrades()
    
    Dim score As Integer
    
    score = ActiveCell.Value
    
    Select Case score
    
    Case 0 To 50.3778337531486
    ActiveCell(1, 2).Value = "TI"
    ActiveCell(1, 2).HorizontalAlignment = xlCenter
    ActiveCell(1, 2).Interior.Color = RGB(0, 255, 0)
    ActiveCell(1, 3).Value = "No"
    ActiveCell(1, 3).HorizontalAlignment = xlCenter
    
    Case 50.3778337531487 To 176.32241813602
    ActiveCell(1, 2).Value = "ARI"
    ActiveCell(1, 2).HorizontalAlignment = xlCenter
    ActiveCell(1, 2).Interior.Color = RGB(255, 0, 0)
    ActiveCell(1, 3).Value = "No"
    ActiveCell(1, 3).HorizontalAlignment = xlCenter
    
    Case 176.32241813603 To 251.889168765743
    ActiveCell(1, 2).Value = "PRI"
    ActiveCell(1, 2).HorizontalAlignment = xlCenter
    ActiveCell(1, 2).Interior.Color = RGB(255, 255, 0)
    ActiveCell(1, 3).Value = "No"
    ActiveCell(1, 3).HorizontalAlignment = xlCenter
    
    Case 251.889168765744 To 302.267002518892
    ActiveCell(1, 2).Value = "TI unknown"
    ActiveCell(1, 2).HorizontalAlignment = xlCenter
    ActiveCell(1, 2).Interior.Color = RGB(0, 255, 0)
    ActiveCell(1, 3).Value = "No"
    ActiveCell(1, 3).HorizontalAlignment = xlCenter
    
    Case 302.267002518892 To 428.211586901763
    ActiveCell(1, 2).Value = "ARI unknown"
    ActiveCell(1, 2).HorizontalAlignment = xlCenter
    ActiveCell(1, 2).Interior.Color = RGB(255, 0, 0)
    ActiveCell(1, 3).Value = "No"
    ActiveCell(1, 3).HorizontalAlignment = xlCenter
    
    Case 428.211586901764 To 503.778337531486
    ActiveCell(1, 2).Value = "PRI unknown"
    ActiveCell(1, 2).HorizontalAlignment = xlCenter
    ActiveCell(1, 2).Interior.Color = RGB(255, 255, 0)
    ActiveCell(1, 3).Value = "No"
    ActiveCell(1, 3).HorizontalAlignment = xlCenter
    
    Case 503.778337531487 To 508.816120906801
    ActiveCell(1, 2).Value = "TI emergency"
    ActiveCell(1, 2).HorizontalAlignment = xlCenter
    ActiveCell(1, 2).Interior.Color = RGB(0, 255, 0)
    ActiveCell(1, 3).Value = "Yes"
    ActiveCell(1, 3).HorizontalAlignment = xlCenter
    
    Case 508.816120906802 To 518.891687657431
    ActiveCell(1, 2).Value = "ARI emergency"
    ActiveCell(1, 2).HorizontalAlignment = xlCenter
    ActiveCell(1, 2).Interior.Color = RGB(255, 0, 0)
    ActiveCell(1, 3).Value = "Yes"
    ActiveCell(1, 3).HorizontalAlignment = xlCenter
    
    Case 518.891687657432 To 528.96725440806
    ActiveCell(1, 2).Value = "PRI emergency"
    ActiveCell(1, 2).HorizontalAlignment = xlCenter
    ActiveCell(1, 2).Interior.Color = RGB(255, 255, 0)
    ActiveCell(1, 3).Value = "Yes"
    ActiveCell(1, 3).HorizontalAlignment = xlCenter
    
    Case 528.96725440807 To 609.571788413098
    ActiveCell(1, 2).Value = "SK"
    ActiveCell(1, 2).HorizontalAlignment = xlCenter
    ActiveCell(1, 2).Interior.Color = RGB(0, 0, 255)
    ActiveCell(1, 3).Value = "No"
    ActiveCell(1, 3).HorizontalAlignment = xlCenter
    
    Case 609.571788413099 To 739.478589420655
    ActiveCell(1, 2).Value = "FE"
    ActiveCell(1, 2).HorizontalAlignment = xlCenter
    ActiveCell(1, 2).Interior.Color = RGB(0, 255, 255)
    ActiveCell(1, 3).Value = "No"
    ActiveCell(1, 3).HorizontalAlignment = xlCenter
    
    Case 739.478589420656 To 881.612090680101
    ActiveCell(1, 2).Value = "PRF"
    ActiveCell(1, 2).HorizontalAlignment = xlCenter
    ActiveCell(1, 2).Interior.Color = RGB(255, 0, 255)
    ActiveCell(1, 3).Value = "No"
    ActiveCell(1, 3).HorizontalAlignment = xlCenter
    
    Case 881.612090680102 To 982.367758186398
    ActiveCell(1, 2).Value = "FRD"
    ActiveCell(1, 2).HorizontalAlignment = xlCenter
    ActiveCell(1, 2).Interior.Color = RGB(255, 153, 0)
    ActiveCell(1, 3).Value = "No"
    ActiveCell(1, 3).HorizontalAlignment = xlCenter
    
    Case 982.367758186399 To 984.886649874055
    ActiveCell(1, 2).Value = "SK emergency"
    ActiveCell(1, 2).HorizontalAlignment = xlCenter
    ActiveCell(1, 2).Interior.Color = RGB(0, 0, 255)
    ActiveCell(1, 3).Value = "Yes"
    ActiveCell(1, 3).HorizontalAlignment = xlCenter
    
    Case 984.886649874056 To 989.92443324937
    ActiveCell(1, 2).Value = "FE emergency"
    ActiveCell(1, 2).HorizontalAlignment = xlCenter
    ActiveCell(1, 2).Interior.Color = RGB(0, 255, 255)
    ActiveCell(1, 3).Value = "Yes"
    ActiveCell(1, 3).HorizontalAlignment = xlCenter
    
    Case 989.92443324938 To 994.962216624685
    ActiveCell(1, 2).Value = "PRF emergency"
    ActiveCell(1, 2).HorizontalAlignment = xlCenter
    ActiveCell(1, 2).Interior.Color = RGB(255, 0, 255)
    ActiveCell(1, 3).Value = "Yes"
    ActiveCell(1, 3).HorizontalAlignment = xlCenter
    
    Case 994.962216624686 To 1000
    ActiveCell(1, 2).Value = "FRD emergency"
    ActiveCell(1, 2).HorizontalAlignment = xlCenter
    ActiveCell(1, 2).Interios.Color = RGB(255, 153, 0)
    ActiveCell(1, 3).Value = "Yes"
    ActiveCell(1, 3).HorizontalAlignment = xlCenter
    
    Case Else
    MsgBox "No score entered"
    
    End Select
    
    End Sub
    Last edited by SamT; 05-20-2015 at 10:02 AM.

Posting Permissions

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