+ Reply to Thread
Results 1 to 4 of 4

Inserting variable into "destination" code

  1. #1
    Registered User
    Join Date
    10-12-2015
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    8

    Inserting variable into "destination" code

    Hi Guys, been struggling to find a solution to this for a couple of days. Fairly new to VBA. I'm trying the write a macro that takes the last line with data in a spreadsheet and fills it down to the line below (copying formulas etc).

    With a cell on the last row selected (will work on getting it to automatically select the last row later), I can use this:

    ActiveCell.EntireRow.Select
    Selection.AutoFill Destination:=Rows("297:298"), Type:=xlFillDefault


    but only if the last row is 297. So I want to replace 297 and 298 with the last row and the next row on any given sheet.

    I can find the last row and next row

    LastRow = Worksheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row
    NextRow = LastRow + 1


    so I want to insert the result of those variables into the statement above, like:

    ActiveCell.EntireRow.Select
    Selection.AutoFill Destination:=Rows("LastRow:NextRow"), Type:=xlFillDefault


    But can't figure out how to do this. Can anyone help?

    Cheers

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,418

    Re: Inserting variable into "destination" code

    Maybe:

    Please Login or Register  to view this content.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    10-12-2015
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    8

    Re: Inserting variable into "destination" code

    YES! Thank you TMS!!!

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,418

    Re: Inserting variable into "destination" code

    You're welcome.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 1
    Last Post: 04-01-2014, 03:21 AM
  2. [SOLVED] Paste in "match destination format" macro code
    By Hopelesslylost in forum Excel General
    Replies: 6
    Last Post: 12-05-2012, 01:57 PM
  3. vba code: value of a variable which is stored in a variable ( equal to Pointers in "C")
    By vidyuthrajesh in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-18-2012, 04:24 PM
  4. Error msgs: "Object varible or with block variable not set"; "subscript out of range"
    By menyanthe in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 10-26-2009, 04:58 PM
  5. Inserting country code "1" into an existing column of phone numbers
    By Snowyky in forum Excel - New Users/Basics
    Replies: 6
    Last Post: 03-18-2008, 06:06 PM
  6. [SOLVED] inserting a conditional "go to" command on a excel "if" function
    By velasques in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 03-10-2006, 04:20 PM
  7. use variable in Workbooks("book1").Worksheets("sheet1").Range("a1"
    By Luc in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-28-2005, 04:05 PM

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