Looking for a Vba count solution

MrStanley

New Member
Joined
Feb 20, 2012
Messages
17
Hello, Can somebody please help me on using a Vba count method of solving the following. I'm attempting to get a football stat of how many games ago a team last Won Drew or Lost. Column A2 contains the first team and the range of B2:AU2 the results (B2 is the most recent result) at the end of the season of 46 games AU2 will be the last result.
A typical example is L L L L L W W D etc, so they last won 6 games ago, last Draw 8 games ago and last loss 1 game ago. I would like the results to go into BA2,BB2 and BC2.
If someone can get me started i'll try and apply the solution to all the teams in Col A.
Many Thanks Robert
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Last edited:
Upvote 0
Robert,

Give this code a try.

Code:
Option Explicit


Sub LastLoss()


Dim x As Integer
Dim y As String
Dim col As Range
Dim i As Integer
Dim lc As Integer


lc = Cells(2, Columns.Count).End(xlToLeft).Column
For x = 1 To 3
        Select Case x
            Case 1
                y = "W"
                Set col = Range("BA2")
            Case 2
                y = "D"
                Set col = Range("BB2")
            Case 3
                y = "L"
                Set col = Range("BC2")
        End Select
        
    For i = 3 To lc
        If Cells(2, i) = y Then
            col.Value = i - 2
            GoTo skip
        End If
    Next i
skip:
Next x


End Sub
 
Upvote 0
Many Thanks JonXL, I was so fixated on a count loop solution I didn't even consider other methods, I think I need to step back sometimes and think more.

Also many thanks to frank_AL I haven't tested your solution yet but it does explain to me why I didn't get anywhere near achieving what you've written...phew!

Thanks both
Regards Robert
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,983
Messages
6,122,591
Members
449,089
Latest member
Motoracer88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top