Consulting

Results 1 to 3 of 3

Thread: Fill in a row until bottom of the table

  1. #1
    VBAX Regular
    Joined
    Sep 2020
    Posts
    62
    Location

    Fill in a row until bottom of the table

    Hello,

    I'm attempting to take the date in cell A2, and paste it (the value not the formula) in each cell in column A, starting in A9, but have it stop at the bottom of the table. In the attachment, the end result should have 3/15/2021 in cells A9 through A400.

    However, next week another data set will be pasted below this one. I have the A2 formula structured to show 3/22/2021 starting next week. Next week's data will essentially be taking up cells B401 through P800. When I run the macro again, I need it to take the date in A2 (which will show 3/22/2021 starting next week), and have it pasted in column A in only the blank cells (A401:A800, along side the new data). Once again having it stop at the end of the table.

    So after two weeks the end result should have 3/15/2021 from A9:A400, with its data to the right of it in columns B:P. Then have 3/22/2021 from A401:A800. Then so on and so on with each passing week. Don't worry about changing the date when testing, that will occur on it's own with each passing week based on how the formula is setup for it.

    I hope that makes sense...Thanks so much in advance.
    Attached Files Attached Files

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Try this
    Private Sub Worksheet_Change(ByVal Target As Range)
        If Target.Address = "$A$2" Then FillDates
    End Sub
    
    
    Sub FillDates()
        Range(Cells(Rows.Count, "A").End(xlUp).Offset(1), Cells(Cells(Rows.Count, "B").End(xlUp).Row, "A")) = Range("$A$2").Value
    End Sub
    Assumes new B:P exists before A2 changes. Doesn't matter how deep B:P is.
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  3. #3
    VBAX Regular
    Joined
    Sep 2020
    Posts
    62
    Location
    Quote Originally Posted by SamT View Post
    Try this
    Private Sub Worksheet_Change(ByVal Target As Range)
        If Target.Address = "$A$2" Then FillDates
    End Sub
    
    
    Sub FillDates()
        Range(Cells(Rows.Count, "A").End(xlUp).Offset(1), Cells(Cells(Rows.Count, "B").End(xlUp).Row, "A")) = Range("$A$2").Value
    End Sub
    Assumes new B:P exists before A2 changes. Doesn't matter how deep B:P is.
    Exactly what I was looking for.

    Thanks!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •