Formula or Code for writing the difference between the 2 highest number

carole CD

New Member
Joined
Mar 11, 2016
Messages
10
Good afternoon

I need some help with a file (betting scores). I need a formula or some code to be able to calculate the difference between the highest score (column W) and write it in front of the highest score in column Y.
But on the same page I have the different race (can be 7 or 15)I have empty rows between the races. If you do a code a need to go through every sheet in the workbook.
I have tried few thing but my code always come back like it's done nothing and my formula work if I give a range but I can not change all the time (daily file).
 

Attachments

  • 2024-06-11 14_51_44-20240608 Gap Test - Excel.png
    2024-06-11 14_51_44-20240608 Gap Test - Excel.png
    60.8 KB · Views: 25
First column (with the word Tab) is in col A and Points Total is in col W, correct?
Try this:
VBA Code:
Sub caroleCD_1()
Dim c As Range, f As Range, g As Range
Dim k As Long, h1 As Double, h2 As Double
Dim sAddress As String
Dim ws As Worksheet
Application.ScreenUpdating = False
 
For Each ws In ThisWorkbook.Worksheets  'If you do a code a need to go through every sheet in the workbook.
    ws.Activate
    With Range("A:A")
        Set c = .Find(What:="Tab", LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, _
        SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
        If Not c Is Nothing Then
            sAddress = c.Address
            Do
               k = c.End(xlDown).Row
               Set f = Range(Cells(c.Row + 1, "W"), Cells(k, "W"))
               h1 = WorksheetFunction.Large(f, 1)
               h2 = WorksheetFunction.Large(f, 2)
               '=INDEX(K:K,MATCH(LARGE(L:L,1),L:L,FALSE),1)
    '           Debug.Print h1 & " : " & h2
               For Each g In f
                    If g = h1 Then g.Offset(, 2) = h1 - h2
               Next
               
               Set c = .FindNext(c)
            Loop While Not c Is Nothing And c.Address <> sAddress
        End If
    
    End With
Next
Application.ScreenUpdating = True
End Sub

carole CD 1.xlsm
ABCDEFGHIJKLMNOPQRSTUVWXYZAA
1DODPoints TotalNo of 3'sHigh Pts GapPrevious Form PointsClass
21AMELIA PARK PLATE [80,000]
3Type : 2 OPEN
411:591000m, TURF S(7)
5
6TabForm L3WgtHorseBPJockeyTrainer
713x158.0WEST STAR5CHRIS PARNHAMS MILLER-835111833
8245x58.0BRAZEN BID1B PARNHAMS MILLER017301
930x56.0SOUTHERN SCANDAL2W PIKEDANIEL & BEN PEARCE015401
104856.0COONDLE4J WHITINGLOU LUCIANI
115-56.0CAPORETTO6LUKE CAMPBELL (a2)N PARNHAM08301
126-56.0SALSA SMASH4J BROWNJ TAYLOR09201
137-54.0FAVOURITE SONGS3JADE MC NAUGHTLUKE FERNIE06201
14
15
16
172BISLEY WORKWEAR HANDICAP [80,000]
18Type : 2U BM78+
1912:341000m, TURF S(7)
20
21TabForm L3WgtHorseBPJockeyTrainer
22184659.0BEADS1P HARVEYS WOLFE422511
23241x58.0YONGA LASS7W PIKEG & A WILLIAMS019301
2439x157.0CASH AWAY6HOLLY WATSONMISTY BAZELEY2.526732
25417x57.0RUSSIAN TO THE BAR5CHRIS PARNHAMLUKE FERNIE020401
26590x56.0EEYORE WAYZ4P CARBERYRAQUEL REID018501
276x3255.0GODDESS OF GIVING2J WHITINGLOU LUCIANI1.5296321
28769x55.0TOP OF THE POPS3B PARNHAMC & M GANGEMI021401
29
30
31
323NATIONAL PUMP AND ENERGY HANDICAP [60,000]
33Type : 2U 1MW
3413:091000m, TURF S(7)
35
36TabForm L3WgtHorseBPJockeyTrainer
37125x60.0BAYEZID2MADI DERRICK (a1.5)T ROBERTSON025601
38242159.0CAPRE OMNIA5S PARNHAMDYLAN BAIRSTOW1.524531
39351x58.5BERBERE4W PIKEG & A WILLIAMS0288201
40467x57.5OUR ROCKY BAY3B LOUIST MARTINOVICH013301
41517857.0BARNEY'S WORLD8CHRIS PARNHAMLUKE FERNIE-0.526612
426x5856.5LITTLE STRAWBERRY6HOLLY WATSONMITCHELL PATEMAN319411
43765x56.5MISS DRAKOVA7B PARNHAMN PARNHAM020401
4480x656.5ON THE FULL1LAQDAR RAMOLYJ TAYLOR524611
Sheet2
 
Upvote 1
Solution

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
You're welcome, glad to help & thanks for the feedback.:)
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

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