code error 1004

zrx1200

Well-known Member
Joined
Apr 14, 2010
Messages
622
Office Version
  1. 2019
Platform
  1. Windows
Hell why am I getting code error (1004) on this code/ Highlighted in red.

Code:
 ' Get the last row with text
    Dim LastRow As Long
    Dim i As Long
    
    LastRow = Cells(Rows.count, 34).End(xlUp).row
   
    ' Use LastRow in loop
    For i = 3 To LastRow
        ' Check if cell has text name
       [COLOR=#ff0000] If Cells(i, 34).value = name And Cells.Offset(i, 1).value = Date And Cells.Offset(i, 1).value = Null Then[/COLOR]
'           If Cells.Offset(i, 3).value = "" Then
              MsgBox Cells(i, 34).value
              MsgBox "OK"
           End If
            
            MsgBox i
'        End If
    Next i
    ' Print total
    Debug.Print "Name not found"
 
Last edited:

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
What is name? I think that is a key word that you can't use as a variable.
Also, once your get that sorted out, you are never going to get inside the IF loop because you are requiring that cells.offset(i,1)=Date AND that cells.offset(i,1) is Null. I don't think those will ever both be true for the same i.

I hope this helps.

Ken
 
Upvote 0
Further to Ken's comments ...

Cells refers to the entire worksheet, so Cells.Offset(i,1) is not a valid reference. I'm guessing you mean Cells(i,35)?

Also, a cell's value can be blank, but it can't be equal to Null.
 
Upvote 0
Further to Ken's comments ...

Cells refers to the entire worksheet, so Cells.Offset(i,1) is not a valid reference. I'm guessing you mean Cells(i,35)?

Also, a cell's value can be blank, but it can't be equal to Null.

Yes in red giving me error 91 invalid object so....

So, what do I need to accomplish the following.

column AH find name and make sure column AI Date value =Date if yes check if column AK has time value in it (these will all be same row)

if in red don't come true find the next name and test again (loop) ? until found then check AK for time value once again.
 
Upvote 0
I'm not totally clear, but if you want to identify all rows where:
Column AH = MyName, and
Column AI = MyDate, and
Column AK is blank,

you could modify your code like this:

Code:
For i = 3 To LastRow
    If Cells(i, "AH").Value = MyName And Cells(i, "AI").Value = MyDate And Cells(i, "AK").Value = "" Then _
        MsgBox "Matching name and date in row " & i & ", but blank in column AK"
Next i

You code doesn't specify values for MyName and MyDate. Where do these come from?

I'm also not clear whether your Date is meant to be the VBA Date function (= today's date) or a date specified by the user?
 
Upvote 0
I'm not totally clear, but if you want to identify all rows where:
Column AH = MyName, and
Column AI = MyDate, and
Column AK is blank,

you could modify your code like this:

Code:
For i = 3 To LastRow
    If Cells(i, "AH").Value = MyName And Cells(i, "AI").Value = MyDate And Cells(i, "AK").Value = "" Then _
        MsgBox "Matching name and date in row " & i & ", but blank in column AK"
Next i

You code doesn't specify values for MyName and MyDate. Where do these come from?

I'm also not clear whether your Date is meant to be the VBA Date function (= today's date) or a date specified by the user?

Thanks for your input. I now can enter the full testing phase, as I now have what I wish see from my procedure.
 
Upvote 0

Forum statistics

Threads
1,224,826
Messages
6,181,192
Members
453,021
Latest member
pingpong7117

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top