Professional Documents
Culture Documents
Excel A Macro To Find A Particular Number in A List
Excel A Macro To Find A Particular Number in A List
July 2014
Issue
I'm trying to write a macro in Excel that must perform the below functions:
When we click on the command button, it should prompt for entering the number in the input box.
After entering the number, it should take us to the cell that has the number.
and coresponding cell should be filled with current time.
The template is as below: When I click the command button and enter the number 307304 in the input box. it should take
me to the particular cell and where start time should be captured. If I click again the end time should be captured. (these
times should be current time).
Employee # Start Time End Time
307301
307302
307303
307304
307305
307306
307307
307308
307309
307310
Solution
ry this. The routine to use is doTimeStamp The idea is that you would attach this routine to the command button. When yo
click on it, it will ask for emp id and will fill in the start date (if it is blank) or end date (if it is blank) and then prompt you again
for the next id. It will continue to ask you for id till you enter a blank and that point it will quit.
Option Explicit
Public Sub doTimeStamp()
Dim lRow
As Long
Dim sSearchText As String
Dim lEmpID
As Long
Dim sTgtSheet
As String
Dim Cell
As Range
Dim iLookAt
As Integer
Dim iSearchDir
As Integer
Dim iSearchOdr
As Integer
If (bFullString) _
Then
iLookAt = xlWhole
Else
iLookAt = xlPart
End If
If (bLastOccurance) _
Then
iSearchDir = xlPrevious
Else
iSearchDir = xlNext
End If
If Not (bFindRow) _
Then
iSearchOdr = xlByColumns
Else
iSearchOdr = xlByRows
End If
With rngSearch
If (bLastOccurance) _
Then
Set Cell = .Find(sLookFor, .Cells(1, 1), xlValues, iLookAt, iSearchOdr, iSearchDir)
Else
Set Cell = .Find(sLookFor, .Cells(.Rows.Count, .Columns.Count), xlValues, iLookAt, iSearchOdr, iSearchDir)
End If
End With
If Cell Is Nothing Then
getItemLocation = 0
ElseIf Not (bFindRow) _
Then
getItemLocation = Cell.Column
Else
getItemLocation = Cell.Row
End If
Set Cell = Nothing
End Function
Note that
Thanks to rizvisa1 for this tip.
This document entitled Excel - A macro to find a particular number in a list from Kioskea (en.kioskea.net) is made available under the Creative
Commons license. You can copy, modify copies of this page, under the conditions stipulated by the license, as this note appears clearly.