+ Reply to Thread
Results 1 to 6 of 6

AutoFill the first emty column based on the values of the last filled column

Hybrid View

  1. #1
    Registered User
    Join Date
    09-19-2013
    Location
    athens
    MS-Off Ver
    Excel 2010
    Posts
    12

    AutoFill the first emty column based on the values of the last filled column

    Dear all,

    I'm new user of Excel VBA.

    The following code autofills column EX based on the values of column EW:

        Sub mfill()
              Columns("EW:EW").Select
              Selection.AutoFill destination:=Columns("EW:EX"), Type:=xlFillDefault
        End Sub
    I would like to find a way to automatically find the last filled column and use this to autofill the column next to that. In the above example I would like to change EW with the last filled column and EX with the column next to that. How can I do that?

    Thanks a lot!
    Last edited by runneer; 09-20-2013 at 01:58 AM. Reason: Correct incomplete code, tag code

  2. #2
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: AutoFill the first emty column based on the values of the last filled column

    Maybe:

    Sub runneer()
    Range(Cells(1, ActiveSheet.UsedRange.Columns.count), Cells(ActiveSheet.UsedRange.Rows.count, ActiveSheet.UsedRange.Columns.count + 1)).Interior.ColorIndex = 6
    End Sub

  3. #3
    Registered User
    Join Date
    09-19-2013
    Location
    athens
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: AutoFill the first emty column based on the values of the last filled column

    Thanks a lot John for your help. I tried your Sub() but it changes the interior color of the last filled column and column next to that to yellow. It does not auto fill the values of the first empty column though. Is there anyway to do that?
    Thanks!

  4. #4
    Registered User
    Join Date
    09-19-2013
    Location
    athens
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: AutoFill the first emty column based on the values of the last filled column

    I played around with your suggestion John together with the help from http://msdn.microsoft.com/en-us/libr.../ff195345.aspx and I think I solved my problem! Here is the code:

    Sub mfill()
    
        Set SourceRange = Range(Cells(1, ActiveSheet.UsedRange.Columns.Count), Cells(ActiveSheet.UsedRange.Rows.Count, ActiveSheet.UsedRange.Columns.Count))
        Set fillRange = Range(Cells(1, ActiveSheet.UsedRange.Columns.Count), Cells(ActiveSheet.UsedRange.Rows.Count, ActiveSheet.UsedRange.Columns.Count + 1))
        SourceRange.AutoFill destination:=fillRange, Type:=xlFillDefault
    End Sub
    Last edited by runneer; 09-20-2013 at 01:58 AM. Reason: tag code

  5. #5
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: AutoFill the first emty column based on the values of the last filled column

    runneer. Glad you got a solution. I know my suggestion change the color. It was my mistake. I was testing for filling the last used column and offsetting one column. I often test that way. I lost track of filling the formula as you required.

  6. #6
    Registered User
    Join Date
    09-20-2013
    Location
    United States
    MS-Off Ver
    Excel 2003
    Posts
    1

    Re: AutoFill the first emty column based on the values of the last filled column

    no help[

+ 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. Need help with Macro to autofill formula in Column B based on length of Column A
    By soxsrules in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-06-2013, 02:43 PM
  2. Replies: 4
    Last Post: 12-04-2012, 02:24 AM
  3. Autofill a column based on number in adjacent column
    By fbonetti in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 04-08-2011, 04:19 PM
  4. Autofill one column based on another column using a certain logic
    By arnabarnab in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-09-2009, 02:38 AM
  5. [SOLVED] Find emty cell in column and insert value
    By Mikus in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-17-2005, 09:05 AM

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