Search for the last of a certain value with VBA in Excel



Search for the last of a certain value with VBA in Excel. Enter out time for the last of the same value in a list. Check out my online courses www.easyexcelanswers.com/courses.html
All my courses include online support and a user manual
Let me teach you the VBA that I have learn in my five years of consulting

Let’s take the frustration out of user forms

Become an Affiliate and earn 25% on Course Sales

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

I am able to provide online help on your computer at a reasonable rate.

I use a Blue condenser Microphone to record my videos, here is the link

Check out Crowdcast for creating your webinars

If you need to buy Office 2019 follow

I use Tube Buddy to help promote my videos
Check them out

Follow me on Facebook

TWEET THIS VIDEO

Follow me on twitter
easyexcelanswers

IG @barbhendersonconsulting

You can help and generate a translation to you own language

*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.

Code
Sub access()
Dim barcode As String
Dim rng As Range
Dim rownumber, fstrow As Long
Dim cell
Dim Total As Double
Dim Timein As Date
Dim Timeout As Date

barcode = ActiveSheet.Cells(1, 2)
If barcode (does not equal) “” Then
‘search for barcode
Set rng = ActiveSheet.Range(“a:a”).Find(what:=barcode, _
LookIn:=xlFormulas, LookAt:=xlWhole, SearchOrder:=xlByRows, _
searchdirection:=xlNext, MatchCase:=False, SearchFormat:=False)
If rng Is Nothing Then
restart:
ActiveSheet.Range(“a:a”).Find(“”).Select
ActiveCell.Value = barcode
ActiveCell.NumberFormat = “@”
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = Date & ” ” & Time
ActiveCell.NumberFormat = “d/m/yyyy h:mm AM/PM”
ActiveSheet.Cells(1, 2) = “”
GoTo ende
Else
fstrow = rng.Row
rownumber = Sheet1.Range(“a:a”).Find(what:=barcode, after:=ActiveSheet.Cells(fstrow, 1), _
searchdirection:=xlPrevious).Row
ActiveSheet.Cells(rownumber, 3).Select
If Not IsEmpty(ActiveCell.Value) Then
GoTo restart
End If
ActiveSheet.Cells(rownumber, 1).Select
ActiveCell.Offset(0, 2).Select
ActiveCell.Value = Date & ” ” & Time
ActiveCell.NumberFormat = “m/d/yyyy h:mm AM/PM”
Timein = CDate(Cells(rownumber, 2).Value)
Timeout = CDate(Cells(rownumber, 3).Value)
Total = TimeValue(Timeout) – TimeValue(Timein)
Debug.Print Total
Debug.Print Format(Total, “hh:mm:ss”)
Cells(rownumber, 4).NumberFormat = “hh:mm:ss”
Cells(rownumber, 4).Value = Total
Debug.Print “Number of hours = ” & Total * 24
ActiveSheet.Cells(1, 2) = “”
End If
ActiveSheet.Cells(1, 2) = “”
End If
ende:
ActiveSheet.Cells(1, 2).Select
End Sub

Watch more new videos about Excel Office | Synthesized by Mindovermetal English

Rate this post

Bài viết liên quan

Theo dõi
Thông báo của
guest
0 Comments
Phản hồi nội tuyến
Xem tất cả bình luận