Need help with script or formula
Solved/Closed
josh07429
Posts
14
Registration date
Friday 23 June 2017
Status
Member
Last seen
20 November 2017
-
23 Jun 2017 à 12:28
josh07429 - 5 Jul 2017 à 12:18
josh07429 - 5 Jul 2017 à 12:18
Related:
- Need help with script or formula
- Logitech formula vibration feedback wheel driver - Download - Drivers
- Ubuntu startup script - Guide
- Credit summation formula - Guide
- Windows startup script - Guide
- Student position formula in excel ✓ - Excel Forum
2 responses
TrowaD
Posts
2921
Registration date
Sunday 12 September 2010
Status
Contributor
Last seen
27 December 2022
555
26 Jun 2017 à 11:19
26 Jun 2017 à 11:19
Hi Josh,
Give the following code a try:
Hope you like it.
Best regards,
Trowa
Give the following code a try:
Sub RunMe()
Dim x, y As Integer
y = 2
NewDate:
x = 0
If Range("B" & y) <> vbNullString Then
Range("C" & y).Value = Range("B" & y).Value
x = 1
End If
Do
If Range("A" & y) = Range("A" & y - 1) And _
Range("B" & y) <> vbNullString And _
x < 2 Then
Range("C" & y).Value = Range("B" & y).Value
x = x + 1
End If
y = y + 1
If Range("A" & y) <> Range("A" & y - 1) Then GoTo NewDate
Loop Until Range("A" & y) = vbNullString
End Sub
Hope you like it.
Best regards,
Trowa
TrowaD
Posts
2921
Registration date
Sunday 12 September 2010
Status
Contributor
Last seen
27 December 2022
555
4 Jul 2017 à 11:52
4 Jul 2017 à 11:52
Hi Josh,
Quite the puzzle :)
See if the following code does the job:
Let me know how the code performs!
Best regards,
Trowa
Quite the puzzle :)
See if the following code does the job:
Sub RunMe()
Dim x, y, HighVal, SecHighVal, Rep As Integer
Dim mDate As Date
x = 2
y = 2
NextDate:
Do
mDate = Range("A" & x)
y = y + 1
Loop Until mDate <> Range("A" & y)
Range(Cells(x, "B"), Cells(y - 1, "B")).Select
HighVal = Application.WorksheetFunction.Max(Selection)
SecHighVal = Application.WorksheetFunction.Large(Selection, 2)
For Each cell In Selection
If cell.Value = HighVal And Rep < 2 Then
cell.Offset(0, 1).Value = cell.Value
Rep = Rep + 1
End If
Next cell
For Each cell In Selection
If cell.Value = SecHighVal And Rep < 2 Then
cell.Offset(0, 1).Value = cell.Value
Rep = Rep + 1
End If
Next cell
Rep = 0
If Range("A" & y).Value = vbNullString Then Exit Sub
x = y
GoTo NextDate
End Sub
Let me know how the code performs!
Best regards,
Trowa

26 Jun 2017 à 12:56
You're a life saver it worked :)
I only had a minor problem cause the dates have time but I just removed the time on the dates and your script works.
Thanks again.
27 Jun 2017 à 14:29