+ Reply to Thread
Results 1 to 7 of 7

Auto populate cells

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    11-19-2014
    Location
    United States
    MS-Off Ver
    2010
    Posts
    137

    Auto populate cells

    I understand that once a cell is highlighted you can drag it to populate the following cells. Is there a function that can do this automatically to the next populated cell? The reason being is that my report has hundreds of lines and its too time consuming doing this one name at a time.

    What I have now
    Name Grade
    Ted 3
    3
    3
    Susan 4
    3


    What I want
    Name Grade
    Ted 3
    Ted 3
    Ted 3
    Susan 4
    Susan 3


    Thanks

  2. #2
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: Auto populate cells

    Enter in D2 and copy down
    Formula: copy to clipboard
    =LOOKUP("zzzz",A$2:A2)

    Enter in E2 and copy down
    Formula: copy to clipboard
    =LOOKUP(10^308,B$2:B2)

    v A B C D E
    1 Name Grade Name Grade
    2 Ted 3 Ted 3
    3 3 Ted 3
    4 3 Ted 3
    5 Susan 4 Susan 4
    6 3 Susan 3
    7
    If you like my answer please click on * Add Reputation
    Don't forget to mark threads as "Solved" if your problem has been resolved

    "Nothing is so firmly believed as what we least know."
    --Michel de Montaigne

  3. #3
    Forum Contributor
    Join Date
    11-19-2014
    Location
    United States
    MS-Off Ver
    2010
    Posts
    137

    Re: Auto populate cells

    Thanks but is there any way to do this without having to create formulas or extra tables?
    Last edited by yuenk; 11-15-2016 at 02:04 PM.

  4. #4
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: Auto populate cells

    Quote Originally Posted by yuenk View Post
    Thanks but is there any way to do this without having to create formulas or extra tables?
    If formula is not an option you would have to look for a VBA solution.

  5. #5
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,641

    Re: Auto populate cells

    Hi there,

    See if the following code does what you need:

    
    
    Option Explicit
    
    
    Sub CopyNames()
    
        Const iFIRST_ROW_NO As Integer = 1
        Const sCOLUMN_GRADE As String = "B"
        Const sCOLUMN_NAME  As String = "A"
        Const sSHEETNAME    As String = "Sheet1"
    
        Dim rFillDownRange  As Range
        Dim rColumn_Grade   As Range
        Dim lLastRowNo      As Long
        Dim rFirstCell      As Range
        Dim rLastCell       As Range
        Dim wks             As Worksheet
    
        Set wks = ThisWorkbook.Worksheets(sSHEETNAME)
    
        With wks
            Set rColumn_Grade = Intersect(.UsedRange.EntireRow, _
                                          .Columns(sCOLUMN_GRADE))
        End With
    
        With rColumn_Grade
            lLastRowNo = .Rows(.Rows.Count).Row
        End With
    
        Set rFirstCell = wks.Range(sCOLUMN_NAME & iFIRST_ROW_NO)
    
        Do
    
            If rFirstCell.Offset(1, 0).Value = vbNullString Then
    
                  Set rLastCell = rFirstCell.End(xlDown).Offset(-1, 0)
    
                  If rLastCell.Row > lLastRowNo Then
                      Set rLastCell = wks.Range(sCOLUMN_NAME & lLastRowNo)
                  End If
    
                  Set rFillDownRange = Range(rFirstCell, rLastCell)
    
                  With rFillDownRange
                      .Value = .Cells(1, 1).Value
                  End With
    
                  Set rFirstCell = rLastCell.Offset(1, 0)
    
            Else: Set rFirstCell = rFirstCell.Offset(1, 0)
    
            End If
    
        Loop Until rLastCell.Row = lLastRowNo
    
    End Sub
    The highlighted values may be altered to suit your own requirements.


    Hope this helps - please let me know how you get on.

    Regards,

    Greg M

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

    Re: Auto Populate Cells

    Maybe:

    Sub yuenk()
    Dim rcell As Range
    For Each rcell In Range("A2:A" & Range("B" & Rows.Count).End(3).row)
        If rcell = "" Then rcell = rcell.Offset(-1)
    Next rcell
    End Sub

  7. #7
    Forum Contributor
    Join Date
    11-19-2014
    Location
    United States
    MS-Off Ver
    2010
    Posts
    137

    Re: Auto Populate Cells

    Thanks this works! This is simple enough too

+ 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. Macro to auto-populate cells based on content of other cells
    By BristolJGM in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-05-2015, 07:47 PM
  2. How to auto populate various cells
    By tomaustin in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 03-24-2015, 12:16 AM
  3. Replies: 1
    Last Post: 09-29-2014, 12:59 AM
  4. Replies: 3
    Last Post: 02-28-2012, 11:54 AM
  5. Auto populate cells...
    By Synthia in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 01-03-2010, 03:46 PM
  6. Auto-Populate Cells
    By NFJim in forum Excel General
    Replies: 4
    Last Post: 09-24-2009, 02:07 PM
  7. Auto populate of cells
    By tester1305 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 05-26-2009, 09:40 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