+ Reply to Thread
Results 1 to 7 of 7

Excel VB-Copy formula down until adjacent cell (left) is blank?

  1. #1
    Tony P.
    Guest

    Excel VB-Copy formula down until adjacent cell (left) is blank?

    Here is exactly what I am trying to do through VB in Excel:

    Weekly data pull fills colums A:G. Row count is always different. I am
    modifying the data pull through VB, and I have a VLOOKUP formula in cell H2.
    What I want VB to do is copy that formula down column H to the last row (with
    data) each week. I guess I want it to be dynamic so that as rows
    decrease/increase the formula is only copied down to the final row/record.

    I know someone out of this smart group will know how to do this!

    Thanks in advance!

    Tony



  2. #2
    David
    Guest

    RE: Excel VB-Copy formula down until adjacent cell (left) is blank?

    Hi,
    Try this, hope it works for you.
    Sub Macro1()
    Range("G1").Select
    Selection.End(xlDown).Select
    LastRow = ActiveCell.Row
    Range("H2").Select
    Selection.Copy
    ActiveCell.Offset(1, 0).Range("A1:A" & (LastRow - 2)).Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
    ActiveCell.Offset(-1, 0).Range("A1").Select
    End Sub

    Thanks,

    "Tony P." wrote:

    > Here is exactly what I am trying to do through VB in Excel:
    >
    > Weekly data pull fills colums A:G. Row count is always different. I am
    > modifying the data pull through VB, and I have a VLOOKUP formula in cell H2.
    > What I want VB to do is copy that formula down column H to the last row (with
    > data) each week. I guess I want it to be dynamic so that as rows
    > decrease/increase the formula is only copied down to the final row/record.
    >
    > I know someone out of this smart group will know how to do this!
    >
    > Thanks in advance!
    >
    > Tony
    >
    >


  3. #3
    Ron de Bruin
    Guest

    Re: Excel VB-Copy formula down until adjacent cell (left) is blank?

    Hy Tony

    You can try this macro

    Sub test()
    Dim LastRow As Long
    With Worksheets("Sheet1")
    LastRow = .Cells(Rows.Count, "A").End(xlUp).Row
    .Range("H2").AutoFill Destination:=.Range("H2:H" & LastRow) _
    , Type:=xlFillDefault
    End With
    End Sub

    It will fill the formula in H2 to H last cell in column A


    --
    Regards Ron de Bruin
    http://www.rondebruin.nl



    "Tony P." <Tony [email protected]> wrote in message news:[email protected]...
    > Here is exactly what I am trying to do through VB in Excel:
    >
    > Weekly data pull fills colums A:G. Row count is always different. I am
    > modifying the data pull through VB, and I have a VLOOKUP formula in cell H2.
    > What I want VB to do is copy that formula down column H to the last row (with
    > data) each week. I guess I want it to be dynamic so that as rows
    > decrease/increase the formula is only copied down to the final row/record.
    >
    > I know someone out of this smart group will know how to do this!
    >
    > Thanks in advance!
    >
    > Tony
    >
    >




  4. #4
    Tony P.
    Guest

    RE: Excel VB-Copy formula down until adjacent cell (left) is blank

    Worked like a charm, David! Thanks!!!!! Have another one for you when you
    get a second. Subject will be "Delete Entire Row"

    "David" wrote:

    > Hi,
    > Try this, hope it works for you.
    > Sub Macro1()
    > Range("G1").Select
    > Selection.End(xlDown).Select
    > LastRow = ActiveCell.Row
    > Range("H2").Select
    > Selection.Copy
    > ActiveCell.Offset(1, 0).Range("A1:A" & (LastRow - 2)).Select
    > ActiveSheet.Paste
    > Application.CutCopyMode = False
    > ActiveCell.Offset(-1, 0).Range("A1").Select
    > End Sub
    >
    > Thanks,
    >
    > "Tony P." wrote:
    >
    > > Here is exactly what I am trying to do through VB in Excel:
    > >
    > > Weekly data pull fills colums A:G. Row count is always different. I am
    > > modifying the data pull through VB, and I have a VLOOKUP formula in cell H2.
    > > What I want VB to do is copy that formula down column H to the last row (with
    > > data) each week. I guess I want it to be dynamic so that as rows
    > > decrease/increase the formula is only copied down to the final row/record.
    > >
    > > I know someone out of this smart group will know how to do this!
    > >
    > > Thanks in advance!
    > >
    > > Tony
    > >
    > >


  5. #5
    Registered User
    Join Date
    01-04-2013
    Location
    india
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Excel VB-Copy formula down until adjacent cell (left) is blank?

    wow, this is what i was searching for. can you please tell me how to do to it for multiple columns. i have to copy formula in several columns in the same way

  6. #6
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Excel VB-Copy formula down until adjacent cell (left) is blank?

    kcube17,

    This thread is over 7 yrs old and not likely to get a reply. Its better if you create a new thread.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  7. #7
    Registered User
    Join Date
    01-04-2013
    Location
    india
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Excel VB-Copy formula down until adjacent cell (left) is blank?

    thanks arlu. I'm starting a new thread

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1