Copy and paste first and last data row

adamsm

Active Member
Joined
Apr 20, 2010
Messages
444
Hi anyone,

How could I figure out a code that would copy the first and last data row below the row 16 of column "Q" to cell A1 and B1.

Any help on this would be kindly appreciated.

Thanks in advance.
 
One more help If I may ask.

How could the code be adjusted so that it works on a filtered sheet?

Suppose the first row value of column "Q" before filtering is 0001 and last data row is 0004;

When the sheet is filtered the first row value is 0002 and the last data row is 0003.

Having this situation; how could the code be adjusted so that it displays the first visible row and last visible data row of column "Q"

I hope I've made my question clear.

Any help on this would be kindly appreciated.
 
Upvote 0

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Try:

Code:
Public Sub CopyFirstLast()
Dim i   As Long, _
    LR  As Long
    
LR = Range("Q" & Rows.Count).End(xlUp).row
Application.ScreenUpdating = False
For i = 17 To LR
    If Rows(i).Hidden = False And Range("Q" & i).Value <> "" Then
        Range("Q" & i).Copy Destination:=Range("A1")
        Exit For
    End If
Next i
Range("Q" & LR).Copy Destination:=Range("A2")
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,020
Messages
6,122,712
Members
449,093
Latest member
Mnur

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