Count the fifth occurrence of an event with VBA in Excel
Free templates and templates with code are available for purchase for $50 USD
www.easyexcela...
Addition Templates may be available on request
Click this link to check out my one-on-one training www.calendly.co...
For more help visit my website www.easyexcelanswers.com or email me at easyexcelanswers@gmail.com.
Contact me regarding customizing this template for your needs.
Click for online Excel Consulting www.calendly.co...
Are you struggling to update your Microsoft SQL Server data?
I recommend using well-known Excel to update and manage your data in SQL Server using the SQL Spreads Excel add-in.
Click sqlspreads.com... to find out how SQL Spreads works best for non-technical end users and download our free 14-day trial. You will get two months free when purchasing an annual subscription using our link.
I am able to provide online help on your computer at a reasonable rate.
Check out Crowdcast for creating your webinars
app.linkmink.c...
I use Tube Buddy to help promote my videos
Check them out
www.Tubebuddy....
Follow me on Facebook
/ easyexcel.answers
IG @barbhendersonconsulting
You can help and generate a translation to you own language
www.youtube.com...
*this description may contain affiliate links. When you click them, I may receive a small commission at no extra cost to you. I only recommend products and services that I've used or have experience with.
How to insert VBA code in Excel • How to insert VBA code...
Sub bonus()
Dim ldate As Date
Dim ws As Worksheet
Dim id As String
Dim cnt As Long
Dim row As Long
Dim lastrow, erow As Long
Dim home As Worksheet
Set home = Worksheets("Sheet2")
Set ws = Worksheets("Sheet1")
home.Activate
lastrow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).row
r = 2
For r = 2 To lastrow
Cells(r, 1).Select
id = ActiveCell.Value
ws.Activate
ws.Range("D2", "D10000").NumberFormat = "dd-mmm-yy"
erow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).row
cnt = 0
'look for ID in this column
With ws.Range(Cells(2, 10), Cells(erow, 10))
Set c = .Cells.Find(id, LookIn:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
trow = c.row
'make sure it is rental before you count
If ws.Cells(trow, 7).Value = "RENTAL" Then
cnt = 1
End If
Do
'find the other four rentals for this id
c.Value = id
Set c = .Cells.FindNext(c)
trow = c.row
If ws.Cells(trow, 7).Value = "RENTAL" Then
'get the lastdate of the rental
ldate = ws.Cells(trow, 4).Value
cnt = cnt + 1
End If
Loop While cnt (less than) 6
End If
End With
'place the information on the other sheet
home.Activate
home.Cells(r, 2).Value = ldate
home.Cells(r, 2).NumberFormat = "dd-mmm-yy"
home.Cells(r, 3).Value = "$500"
Next r
End Sub
11 сен 2024