+ Reply to Thread
Results 1 to 4 of 4

Autofill query

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    05-08-2009
    Location
    england
    MS-Off Ver
    Excel 2007
    Posts
    223

    Autofill query

    The attached provides an example of a workbook where having unmerged column A it leaves various cells without the necessary name.

    Given the fact that it would be very time consuming to manually scroll through and use the autofill handle to rectify this is there any way that it can be done automatically/ programmatically?

    Obviously any blank cell needs to take the name from the one above it.

    Column A could be of any length and at this point is not sorted so the same name may be found throughout the rows.

    Sheet1 shows the starting data, sheet2 the required format

    Cheers,
    Attached Files Attached Files

  2. #2
    Forum Contributor
    Join Date
    05-08-2009
    Location
    england
    MS-Off Ver
    Excel 2007
    Posts
    223

    Re: Autofill query

    Can this be done?

  3. #3
    Forum Contributor codeslizer's Avatar
    Join Date
    05-28-2013
    Location
    Mumbai, India
    MS-Off Ver
    Excel 2003 - 2010
    Posts
    245

    Re: Autofill query

    Hi Andy,

    Yes, this can be done of course. For this kind of application, you need to control the flow of your code. To do that, you've to closely monitor each one of your instructions on how they react to when you execute them. Following is the code what I have used to cater your needs. Am also attaching your sample file on which I have worked.

    Sub AutoFillColumn()
        Dim firstcell As Range
        Dim lastcell As Range
        Dim v_count As Long
        
        Sheet1.Activate
        Sheet1.Range("A1").Select
        Set firstcell = ActiveCell
        Set lastcell = firstcell.End(xlDown)
        v_count = firstcell.Offset(0, 1).End(xlDown).Row - firstcell.Row
        For i = 1 To v_count
            Range(firstcell, Cells(lastcell.Row - 1, lastcell.Column)).Select
            If Selection.Count > 1000000 Then
                Range(firstcell, Cells(v_count + 1, lastcell.Column)).Select
            End If
            If Selection.Count > 1 Then Selection.FillDown
    LastPart:
            If Selection.End(xlDown).Row = v_count + 1 Then Exit For
            Set firstcell = firstcell.End(xlDown)
            Set lastcell = firstcell.End(xlDown)
            firstcell.Select
        Next i
    End Sub
    I have used column B to get the total filled count so that we can get an bottom limit. This is used to ensure when we reach the last filled row and when there is no bottom limit to the rows when trying to find next filled row.

    v_count = firstcell.Offset(0, 1).End(xlDown).Row - firstcell.Row
    Hope, this helps!

    P.S. I have changed the file format to xlsm so that the macro gets included as xlsx won't store macro codes.
    Attached Files Attached Files
    Last edited by codeslizer; 07-30-2013 at 12:06 PM.
    cOdEsLiZeR - Back after a long break.. Let's sLiZe some more cOdEs!!

  4. #4
    Forum Contributor
    Join Date
    05-08-2009
    Location
    england
    MS-Off Ver
    Excel 2007
    Posts
    223

    Re: Autofill query

    That's great, thank you very much

+ 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. Autofill range query
    By bd528 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-13-2010, 10:28 AM
  2. MS query and adjacent autofill
    By jumpstones in forum Excel General
    Replies: 0
    Last Post: 11-05-2009, 12:22 PM
  3. Autofill(?) Function Query
    By carlosbourn in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 04-14-2008, 12:53 PM
  4. autofill column with values from an access db query?
    By bardschant in forum Excel General
    Replies: 1
    Last Post: 01-23-2008, 07:21 PM
  5. [SOLVED] Database-Query and AutoFill??????
    By mattse_f in forum Excel General
    Replies: 1
    Last Post: 06-30-2005, 07: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