DynamicLastRow

soidog

New Member
Joined
May 26, 2016
Messages
45
Hello,
I've been searching a lot but can't find the answer.
There are a number of cells with text string "DATE" in column "A".
Under every "DATE" there are 0-5 rows with dates, followed by an empty row.
I want to copy the "DATE"-row and the following rows with dates (0-5), offset 11 columns, to column "T" (pls. see code).
Any help is much appreciated.
This is what I have so far:

Code:
Sub LastRow()


Dim c       As range
Dim FA      As String
Dim ws      As Worksheet
Dim LR      As Long


Application.ScreenUpdating = False
Set ws = ActiveSheet


With ws.Columns(1)
    Set c = Cells.Find(What:="DATE", LookAt:=xlWhole)
    FA = c.Address
    LR = range("A:A").CurrentRegion.Rows.Count  'Wrong?
    
    Do
        'range(c, c.Offset(5, 11)).Copy     'This works (static 5 rows)
        range(c, c.Offset(LR, 11)).Copy     'This works not. Rows can be 0-5, not only 5, until first empty row.


        range("T" & Rows.Count).End(xlUp).Offset(2).PasteSpecial


        Set c = .FindNext(c)
    Loop Until c Is Nothing Or c.Address = FA
End With
Application.ScreenUpdating = True
End Sub
/Tom
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
The code runs fine for me both Excel 2010 and 2016 (office 365).

Not sure why it would not work for you.
 
Upvote 0

Forum statistics

Threads
1,215,543
Messages
6,125,423
Members
449,223
Latest member
Narrian

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