+ Reply to Thread
Results 1 to 4 of 4

Autofill with variable instead of reference cell

  1. #1
    Registered User
    Join Date
    09-07-2012
    Location
    DC
    MS-Off Ver
    Excel 2007
    Posts
    3

    Autofill with variable instead of reference cell

    Hi guys,

    new to the forum, so apologies if this is already covered and I didnt find it.

    I want to autofill down a column, based on the presence of data in another column.

    For example, this is the data column that exists:

    a
    a
    b
    b

    And I want to fill down in a second column an if statement:

    =if(a1="a","1","2")

    However, for various reasons related to the usage of this workbook, I cannot rely on the formula remaining present in the source cell of an autofill script.

    Currently, I have this:

    Public Sub autofill()
    Worksheets("Sheet4").Range("B1").autofill Destination:=Range("B1:B" & Cells(Rows.Count, "A").End(xlUp).Row)
    End Sub

    What I need is to replace "Worksheets("Sheet4").Range("B1")" with the formula itself.

    Anyone have a solution here?

    thanks!

    Wiggin

  2. #2
    Valued Forum Contributor tlafferty's Avatar
    Join Date
    04-08-2011
    Location
    United States, Tacoma, WA
    MS-Off Ver
    Excel 2010, Excel 2013 Customer Preview
    Posts
    1,112

    Re: Autofill with variable instead of reference cell

    sure...
    Please Login or Register  to view this content.
    If your question has been satisfactorily addressed, please consider marking it solved. Click the Thread Tools dropdown and select Mark thread as solved.
    Also, you might want to add to the user's reputation by clicking the star icon in the lower left corner of the post with the answer- it's why we do what we do...

    Thomas Lafferty
    Analyst/Programmer

  3. #3
    Registered User
    Join Date
    09-07-2012
    Location
    DC
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Autofill with variable instead of reference cell

    Thanks!

    Just started working with OO programming, so I will probably ask some worthless questions for a couple of months, but ill get there. Thanks for the help.

    best,

    Wiggin

  4. #4
    Registered User
    Join Date
    09-07-2012
    Location
    DC
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Autofill with variable instead of reference cell

    This solution is great, however i want to add one more layer to it, and I cant quite crack it.

    In the same scenario, I want to make sure this macro does not "re-do" any cells that have already been completed by the macro in a previous session (in case formula has to change). For example, if I had this:

    a 1
    a 1
    b 2
    b 2
    a
    a
    b
    b

    what would I need to add to the macro to make sure it didnt redo the formula for the first 4 rows, and applied it only to the last 4 rows?

    Many thanks!!

    John Mc.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

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