Results 1 to 9 of 9

No Macro Experience - Need to run a loop (I think?!) over a set of data for multiple rows

Threaded View

vkelly No Macro Experience - Need to... 10-28-2014, 09:57 AM
Olly Re: No Macro Experience -... 10-28-2014, 10:59 AM
vkelly Re: No Macro Experience -... 10-28-2014, 11:06 AM
Olly Re: No Macro Experience -... 10-28-2014, 11:34 AM
vkelly Re: No Macro Experience -... 10-29-2014, 07:21 AM
vkelly Re: No Macro Experience -... 10-29-2014, 07:33 AM
Olly Re: No Macro Experience -... 10-29-2014, 07:41 AM
vkelly Re: No Macro Experience -... 10-29-2014, 07:49 AM
Olly Re: No Macro Experience -... 10-29-2014, 08:11 AM
  1. #4
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: No Macro Experience - Need to run a loop (I think?!) over a set of data for multiple r

    I would make it neater, by using some UDFs:
    Function BridgeScore(DefectExtent As String, DefectSeverity As String, TrafficFlow As Long, _
                        RoadType As String, OverUnder As String, WaterproofingType As String, _
                        WaterproofingAge As Integer, StructureCondition As Single)
        Dim i As Integer, RunningTotal As Integer
    
        RunningTotal = DefectExtentScore(DefectExtent) * DefectSeverityScore(DefectSeverity)
        RunningTotal = RunningTotal + TrafficScore(TrafficFlow) * 3
        RunningTotal = RunningTotal + RoadTypeScore(RoadType) * 3
        RunningTotal = RunningTotal + OverUnderScore(OverUnder) * 3
        RunningTotal = RunningTotal + WaterproofingTypeScore(WaterproofingType) * 5
        RunningTotal = RunningTotal + WaterproofingAgeScore(WaterproofingAge) * 5
        RunningTotal = RunningTotal + StructureConditionScore(StructureCondition) * 5
        BridgeScore = RunningTotal
    End Function
    
    
    Function DefectExtentScore(DefectExtent As String)
        DefectExtentScore = Asc(Right(DefectExtent, 1)) - 64
    End Function
    
    Function DefectSeverityScore(DefectSeverity As String)
        DefectSeverityScore = WorksheetFunction.Min(CInt(Right(DefectSeverity, Len(DefectSeverity) - 1)), 4)
    End Function
    
    Function TrafficScore(TrafficFlow As Long)
        TrafficScore = WorksheetFunction.Min((TrafficFlow - 1) \ 12000 + 1, 5)
    End Function
    
    Function RoadTypeScore(RoadType As String)
        Select Case RoadType
            Case "Motorway":                    RoadTypeScore = 5
            Case "Trunk Road - Dual":           RoadTypeScore = 4
            Case "Trunk Road - Single":         RoadTypeScore = 3
            Case "County Road":                 RoadTypeScore = 2
            Case "Accommodation Bridge":        RoadTypeScore = 1
            Case Else:                          RoadTypeScore = 0
        End Select
    End Function
    
    Function OverUnderScore(OverUnder As String)
        Select Case OverUnder
            Case "Overbridge":                  OverUnderScore = 1
            Case "Underbridge":                 OverUnderScore = 2
            Case Else:                          OverUnderScore = 0
        End Select
    End Function
    
    Function WaterproofingTypeScore(WaterproofingType As String)
        Select Case WaterproofingType
            Case "None Present":                WaterproofingTypeScore = 5
            Case "Bitumen Emulsion or Unknown": WaterproofingTypeScore = 4
            Case "Mastic Asphalt":              WaterproofingTypeScore = 3
            Case "Bitumen Sheet":               WaterproofingTypeScore = 2
            Case "Sprayed/Liquid":              WaterproofingTypeScore = 1
            Case Else:                          WaterproofingTypeScore = 0
        End Select
    End Function
    
    Function WaterproofingAgeScore(WaterproofingAge As Integer)
        WaterproofingAgeScore = WorksheetFunction.Min((WaterproofingAge - 1) \ 10 + 1, 5)
    End Function
    
    Function StructureConditionScore(StructureCondition As Single)
        Select Case StructureCondition
            Case Is <= 40:  StructureConditionScore = 5
            Case 40 To 60:  StructureConditionScore = 4
            Case 60 To 80:  StructureConditionScore = 3
            Case 80 To 90:  StructureConditionScore = 2
            Case Is > 90:   StructureConditionScore = 1
            Case Else:      StructureConditionScore = 0
        End Select
    End Function

    Then in L5, you can enter:
    Formula: copy to clipboard
    =BridgeScore(D5,E5,F5,G5,H5,I5,J5,K5)

    and copy down. Much neater.
    Last edited by Olly; 10-28-2014 at 11:37 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. VBA Macro to loop text to columns through all rows of data
    By ejb52 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 04-18-2014, 06:16 AM
  2. Macro to loop through and fetch data from multiple websites
    By wishkey in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-20-2013, 05:37 AM
  3. Loop macro for multiple separate graphs from rows of a large data set
    By GlennToms in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-30-2012, 02:12 PM
  4. [SOLVED] Macro to create multiple sheet, copy certain values and loop until end of row data
    By jhoelski in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 02-17-2012, 07:35 AM
  5. loop or macro to retrieve rows of data from other worksheet
    By beatrice25 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 12-17-2008, 12:11 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