Locate first empty cell in range of columns

Ironman

Well-known Member
Joined
Jan 31, 2004
Messages
1,069
Office Version
  1. 365
Platform
  1. Windows
Hi

Sheet 'Daily Tracking' contain years from 1984-2061 in Cols D1:CC1
Rows 2:367 contain days of the year (incl Feb 29)

I'm looking for some code that selects the first cell in the column (searching from the top of the sheet downwards) in the current year (whichever year that is) that does not contain a value or a zero value i.e. blank.

Many thanks!
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
PS - Row 61 is Feb 29 and if it is not a leap year this cell will be blank (no zero value). It therefore needs to be excluded from the selection.
 
Upvote 0
Try this:

VBA Code:
Sub firstblank()
  Dim f As Range
  'If it is the last data of the last row used, for this code, this trick does not send an error when selecting a new row.
  With Range("D" & ActiveSheet.UsedRange.Rows(ActiveSheet.UsedRange.Rows.Count).Row + 1)
    .Value = " "
    .Value = ""
  End With
  Set f = Range("D1", Cells(1, Columns.Count).End(1)).Find(Year(Date), , xlValues)
  If Not f Is Nothing Then
    Range(Cells(2, f.Column), Cells(Rows.Count, f.Column)).SpecialCells(4)(1).Select
  End If
End Sub
 
Upvote 0
Hi Dante, good to hear from you and thanks for replying!

I got a 1004 error with this line:
VBA Code:
Range(Cells(2, f.Column), Cells(Rows.Count, f.Column)).SpecialCells(4)(1).Select
 
Upvote 0
PS - Row 61 is Feb 29 and if it is not a leap year this cell will be blank (no zero value). It therefore needs to be excluded from the selection.

Try this code, it includes the adjustment for the leap year.
VBA Code:
Sub firstblank_2()
  Dim f As Range
  Dim i As Long
  
  Set f = Range("D1", Cells(1, Columns.Count).End(1)).Find(Year(Date), , xlValues)
  If Not f Is Nothing Then
      For i = 2 To Rows.Count
        If Cells(i, f.Column).Value = "" Then
          If i = 61 Then
            If Day(DateSerial(Year(Date), 3, 1) - 1) = 29 Then
              Cells(i, f.Column).Select
              Exit Sub
            End If
          Else
            Cells(i, f.Column).Select
            Exit Sub
          End If
        End If
      Next
  End If
End Sub
 
Upvote 0
Solution
Aw, beautiful, that works brilliantly!

Thank you so much once again Dante!
 
Upvote 0

Forum statistics

Threads
1,223,247
Messages
6,171,007
Members
452,374
Latest member
keccles

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