Last row of Filtered Data

thardin

Board Regular
Joined
Sep 29, 2021
Messages
137
Office Version
  1. 365
Platform
  1. Windows
How do I change this code so this Macro selects the last row of filtered data (offset by 3). right now it overrides data in a filtered range when I run it.

For example, if my data ranges from A1 to A50. How do I make it select A53, even if some of the last rows are hidden?


VBA Code:
Sub Signoff()
'
' Signoff Macro
' Keyboard Shortcut: Ctrl+Shift+S


    Dim strFullDate As String

    strFullDate = Format(Date, "mm.dd.yy")
    
    Range("B" & Rows.Count).End(xlUp).Offset(3).Select
    ActiveCell.FormulaR1C1 = "Terah"
    Range("B" & Rows.Count).End(xlUp).Offset(1).Select
    ActiveCell.FormulaR1C1 = "Completed " & strFullDate
  
End Sub
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
How about
VBA Code:
   Dim Rw As Long
   With ActiveSheet
      If .AutoFilterMode Then
         Rw = Split(.AutoFilter.Range.Address(1, 0), "$")(2)
      Else
         Rw = Range("B" & Rows.Count).End(xlUp).Row
      End If
      .Range("B" & Rw).Offset(3) = "Terah"
   End With
 
Upvote 0
Solution
Well Done! Thanks

I like how you included the IF. That helps a lot.

However, you forgot the 2nd row, but I included it in.
Can you please explain that 4th row of code so I can understand?
Rw = Split(.AutoFilter.Range.Address(1, 0), "$")(2)

Sub test()

Dim Rw As Long
Dim strFullDate As String

strFullDate = Format(Now, "mm.dd.yy")

With ActiveSheet
If .AutoFilterMode Then
Rw = Split(.AutoFilter.Range.Address(1, 0), "$")(2)
Else
Rw = Range("B" & Rows.Count).End(xlUp).row
End If
.Range("B" & Rw).Offset(3) = "Terah"
.Range("B" & Rows.Count).End(xlUp).Offset(1).Select
ActiveCell.FormulaR1C1 = "Completed " & strFullDate
End With

End Sub
 
Upvote 0
However, you forgot the 2nd row
No I didn't, I just showed you how to do it. ;)

This .AutoFilter.Range.Address(1, 0) will return the address of the filter range in the form of A$1:M$771 and the Split function will split that into an array based on the $
As split always returns a 0 based array, the 1st item (index 0) will be A & the 3rd item (index 2) will be 771 which is the last row
 
Upvote 0

Forum statistics

Threads
1,214,548
Messages
6,120,141
Members
448,948
Latest member
spamiki

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