Find 1st blank row to fill in when there is an active filter

Shloime

Board Regular
Joined
Oct 25, 2023
Messages
59
Office Version
  1. 365
  2. 2021
  3. 2019
  4. 2016
Platform
  1. Windows
I'm using VBA code to fill data into a sheet that already contains data, so I need to find the first blank row.
these are the 2 methods use, I prefer the first because it checks all columns, The issue with both is, when i have a filter on the target sheet it will find the last visible cell the same as when i click ctrl + arrow up in the worksheet +1 will be a row hidden by the filter and the code would over write the data there.
Does anyone have a solution to handle this, or a different method to find the first blank row?

VBA Code:
 Debug.Print Sheets("Sheet1").Cells.Find(What:="*", After:=Range("A1"), LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False, SearchFormat:=False).Row + 1
    Debug.Print Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row + 1
 
Try this.
VBA Code:
Sub Macro1()
Dim Frng, Clms&, Bclm&, T&, FBRo&
Clms = ActiveSheet.UsedRange.Rows.Count
For T = 1 To Clms
Set Frng = Rows(T).Find("*")
If Frng Is Nothing Then Bclm = Bclm + 1
Next T
FBRo = Clms - Bclm + 1
End Sub
 
Upvote 0

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
UsedRange includes formatting. This won't impact the last row if the formatting is applied to the whole column but individual formatting will impact it.
If any row heights below your data have been changed that will impact it as well.

there are many blank rows in middle
Depending on what this means another option might be to do a similar thing using current region.
The below looks for the last visible cell in column A then applies CurrentRegion to that, which is the range in all directions from that cell until it hits a fully blank row or column
(ctrl+* or ctrl+A with the cell selected will mimic that behaviour)

VBA Code:
Sub LastRowFilteredDataCurrentRange()

    With Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).CurrentRegion
        Debug.Print .Cells(1).Offset(.Rows.Count).Row
    End With

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,622
Messages
6,173,379
Members
452,514
Latest member
cjkelly15

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