+ Reply to Thread
Results 1 to 6 of 6

Auto fill macro for fields below the active field

  1. #1
    Registered User
    Join Date
    04-09-2014
    Location
    Australia
    MS-Off Ver
    Excel 2003
    Posts
    3

    Auto fill macro for fields below the active field

    I need a simple macro to use for conditional autofill of cells below the active cell (to the end of the sheet) with the text that is being entered in the active cell.

    DESCRIPTION:
    I have two columns of data, the first (call it Col1), has a word number which is unique to each specific word in a foreign language, every cell in this column has a number in it from 1 to 30000. Each number reoccurs many times in cells over the length of this column.

    The other column (call it Col2) is blank. As I type words in english in each cell of this column, I need the macro to autofill the text that I have just entered, into every cell in Col2 where it's Col1 number is a match with the Col1 number where I am typing.

    For example, in one row, Col1 has the number "21" and I type in Col2 the word "run". I need the macro to find every row where the number 21 is found in Col1 and automatically enter "run" into Col2 at that location.

    The macro must only autofill cells which have no data in them. Preferably from that cell down, although if that is not possible, all cells would work seeing we are only replacing blank cells with data.

    Thanks for any help in advance.

  2. #2
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Auto fill macro for fields below the active field

    This if for columns A and B. Change as needed.

    Right click the sheet's tab, View > Code, and paste.

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    04-09-2014
    Location
    Australia
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: Auto fill macro for fields below the active field

    Hi Kenneth, that looks great. I was able to work out how to make it function with the existing column configuration in my document, It works great!! thanks for the help, I just learnt some new stuff. Thanks for the help!!
    Last edited by Macgyver7; 04-09-2014 at 09:25 PM.

  4. #4
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Auto fill macro for fields below the active field

    If you get stuck, post a short example file and I will test it out. There will be a +4 and -4 offset I suspect. Obviously, the rr range has to be set to your column N if that has the numbers.

  5. #5
    Registered User
    Join Date
    04-09-2014
    Location
    Australia
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: Auto fill macro for fields below the active field

    I do have one issue with the macro, that is that when I do a find and replace routine on the translation column, the macro tries to run on each cell that has been changed, this is a big problem because I have 170'000 plus rows of data... yes a long file, and excel crashes.

    Is there a way that I can tell the macro to ignore changes made via find and replace?

    Here is the modified code, I am using it here on a modified table of two columns A and B, A being the translation and B being the compare against number or text.




    Sub Worksheet_Change(ByVal Target As Range)
    Dim c As Range, cc As Range, ccc As Range, r As Range, rr As Range, v As Variant
    Set rr = Range("B1", Range("B" & Rows.Count).End(xlUp)) 'specifies the location of word number or Aramaic
    Set r = Intersect(Target, rr.Offset(0, -1)) 'specifies location of translation column -1 is left 1, 1 is right 1
    If r Is Nothing Then Exit Sub

    On Error GoTo EndNow

    Application.EnableEvents = False
    Application.ScreenUpdating = False

    For Each c In r 'for each cell in column J (translation)
    For Each cc In rr 'for each cell column N (SEDnum)
    Set ccc = cc.Offset(0, -1) 'Column J cell. (translation cell)
    If (IsEmpty(ccc) Or ccc.Value = "") And cc.Value = c.Offset(0, 1).Value Then 'location of word num or Aramaic relative to translation
    ccc.Value = c.Value
    End If
    Next cc
    Next c

    EndNow:
    Application.ScreenUpdating = True
    Application.EnableEvents = True
    End Sub
    Last edited by Macgyver7; 04-11-2014 at 06:21 PM.

  6. #6
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Auto fill macro for fields below the active field

    No. We have been discussing that issue at vbaexpress.com.

    What you can do is to run Application.EnableEvents = False, do your F&R, then set it back to True. This can be done by two buttons but the users need to understand the concept. You could add a cell to show the current status of EnableEvents to help the wayward lost.

+ 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 needed to auto populate fields if an X is placed in a specific field
    By dbasch89 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-31-2012, 04:03 PM
  2. Macro problem - auto fill to last active cell
    By CraigieL in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 10-22-2012, 04:43 AM
  3. Macro or script to auto fill fields
    By Benjamin2008 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-29-2010, 05:28 PM
  4. Auto Fill Field macro
    By chris99923 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-31-2007, 07:35 AM
  5. Macro Auto-Fill Field.
    By Josh in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-04-2005, 06:07 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