0

i am new to VBA. Task here is to find the address of a cell with respect to a variable.

i am using the find option and receiving error

Object Variable or With block variable not set

Using Find option in VBA. searching data is already available in the sheet. when I do it manually its working.

Sub updateddata()
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Dim currentdate As Date
Dim empid As String
Dim attendance As String
Dim namerange As Range
Dim columnadd As String
Dim rowadd As Range
Dim pasterange As Range
    Worksheets("MARK ATTENDANCE").Select
    Range("b6").Select
    Set namerange = Range(Selection, ActiveCell.End(xlDown))
    Range("G5").Select
    currentdate = Left(Range("g5").Value, 10)
    attendance = ActiveCell.Offset(1, 0).Value
    For Each cell In namerange
        empid = cell.Value
        If attendance = "" Then
            ActiveCell.Offset(1, 0).Select
            attendance = ActiveCell.Value
        Else
            Worksheets("Daily Attendance Tracker").Select
            Range("1:1").Select
            columnadd = Selection.Find(What:=currentdate, After:=ActiveCell, LookIn:=xlFormulas _
            , LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
            MatchCase:=False, SearchFormat:=False).Address
            Range("B2:B37").Select
            rowadd = Selection.Find(What:=Trim(empid), After:=ActiveCell, LookIn:=xlFormulas _
            , LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
            MatchCase:=False, SearchFormat:=False).Address
        End If
    Next
End Sub
James Z
  • 12,209
  • 10
  • 24
  • 44

0 Answers0