Test for record dates?

G

Guest

I am looking for code that would check for todays date in column A and if not
found put todays date in the last blank row on the sheet and then put values
of "Count1", "Count2" and "Count3" going across in the same row, columns B,C
and D. If it finds todays date do nothing.
 
G

Guest

Sub lookit()
n = Cells(Rows.Count, "A").End(xlUp).Row + 1
For i = 1 To n
If Cells(i, "A").Value = Date Then Exit Sub
Next

For i = Rows.Count To 1 Step -1
If Application.CountA(Rows(i)) = 0 Then
With Cells(i, "A")
.Value = Date
.Offset(0, 1).Value = "Count1"
.Offset(0, 2).Value = "Count2"
.Offset(0, 3).Value = "Count3"
Exit Sub
End With
End If
Next
End Sub

If today's date is not found, the last empty row is found and the values
entered.
 
G

Guest

For some reason it is going to row 65,000+ on the second part of the code.
It is not putting the date or the count in the cells?
 
G

Guest

You asked for the material to be put in the LAST blank row, not the FIRST
blank row. The last blank row is usually row 65536
 
G

Guest

This is a one line change from the original solution:

Sub lookit()
n = Cells(Rows.Count, "A").End(xlUp).Row + 1
For i = 1 To n
If Cells(i, "A").Value = Date Then Exit Sub
Next

For i = 1 To Rows.Count
If Application.CountA(Rows(i)) = 0 Then
With Cells(i, "A")
.Value = Date
.Offset(0, 1).Value = "Count1"
.Offset(0, 2).Value = "Count2"
.Offset(0, 3).Value = "Count3"
Exit Sub
End With
End If
Next
End Sub

The original started from 65536 and worked backwards looking for a blank
line. This solution starts from row #1 and works forward. The pasting will
occur near your working area rather than at the very bottom of a worksheet.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top