+ Reply to Thread
Results 1 to 7 of 7

Autofill to lastrow

  1. #1
    Registered User
    Join Date
    10-19-2005
    Posts
    45

    Autofill to lastrow

    Hi all,

    I am sure that someone will be able to give me a very quick and simple answer on this one but I have hit a brick wall with it.

    My spreadsheet is a large export from a database and I am using sort within macros to manipulate the data. So that I am able to return it to it's original sort I have inserted a column (A) and I want the numbers 1, 2, 3 etc to run down the column until the last row active in the spreadsheet.

    So, my spreadsheet contains the following:
    A1 = 1
    A2 = 2
    A3 = 3

    What I want to do is autofill A1:A3 to lastrow.

    how do I do this?

    Thanks in advance,

    Pedros.

  2. #2
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    Pedros

    This will do what you require

    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    05-14-2006
    Posts
    104

    Autofill

    Hey,

    You can simply just select the little box to the bottom right hand corner of the cells highlighted e.g a1 a2 a3 then drag all the way down.


    however being as the rest of the data is sorted by a macro u can just add this code to the macro and should do the trick

    Sub Macro1()
    Range("A1") = 1
    Range("A2") = 2
    Range("A3") = 3
    Range("A1:A3").Select
    Selection.AutoFill Destination:=Range("A1:A2653"), Type:=xlFillDefault
    Range("A1:A65536").Select
    Range("A1").Select
    End Sub

  4. #4
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,525
    Hi Pedros,

    Using the last cell in column B as a marker, try the following:

    Please Login or Register  to view this content.
    Hope this helps.

    Robert

  5. #5
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    Zygan

    In your code you have used Range("A1:A2653")

    Pedros required code to autofill to the last active row, your code does not identify the last active row.

  6. #6
    Registered User
    Join Date
    04-24-2004
    Posts
    10
    Sub Macro1()
    'assuming all cells are contiguous
    Dim Rws As Integer
    Columns("A:A").Insert Shift:=xlToRight
    [a1] = "SortNo"
    Rws = [a1].CurrentRegion.Rows.Count
    [a2] = 1
    Range(Cells(2, 1), Cells(Rws, 1)).DataSeries
    End Sub

  7. #7
    Registered User
    Join Date
    10-19-2005
    Posts
    45
    Thanks to everyone for replying!!


    Mudraker and Trebor76, both of your solutions work perfectly.

    I have included mudrackers in my macro and it is now working as I required.

    Thanks again,

    Pedros.

+ 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