Results 1 to 4 of 4

Thread: [RESOLVED] If cell not empty...AUTOFILL VBA (FormulaR1C1)

  1. #1

    Thread Starter
    PowerPoster Radjesh Klauke's Avatar
    Join Date
    Dec 2005
    Location
    Sexbierum (Netherlands)
    Posts
    2,244

    Resolved [RESOLVED] If cell not empty...AUTOFILL VBA (FormulaR1C1)

    Not sure how to explain this, but I'll give it a go.

    I'm importing a csv file. After that I'm adding additional columns and values, all using VBA.
    I have a small issue with adding a R1C1 formula and fill the formula to the bottom.

    Example:

    A1 : xxxxx
    A2: yyyyy
    A3:
    A4: zzzzz
    A5: sssss
    A6: eeeee
    A7: jjjjj


    In Column B I need to add "ready" if the cell next to it is not empty.

    Code:
    With Range("B1")
        .FormulaR1C1 = "=IF(RC[-1]<>"""",""ready"","""")"
        .AutoFill Destination:=Range(.Offset(0, -1), .Offset(0, -1).End(xlDown)).Offset(0, 1)
    End With
    The autofill adds one after the first empty cell and then stops. How do i change it so it will use the usedRange?


    Thanks in advance.


    If you found my post helpful, please rate it.

    Codebank Submission: FireFox Browser (Gecko) in VB.NET, Load files, (sub)folders treeview with Windows icons

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: If cell not empty...AUTOFILL VBA (FormulaR1C1)

    you can try like
    .AutoFill .Resize(.Offset(Rows.Count - .Row, -1).End(xlUp).Row)
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    PowerPoster Radjesh Klauke's Avatar
    Join Date
    Dec 2005
    Location
    Sexbierum (Netherlands)
    Posts
    2,244

    Re: If cell not empty...AUTOFILL VBA (FormulaR1C1)

    Thanks, that did it.
    When the column is comletely empty it returns an error, but I "solved" it by using "on error resume next". Probably not the proper way to solve it, but I'm saved for the moment.


    If you found my post helpful, please rate it.

    Codebank Submission: FireFox Browser (Gecko) in VB.NET, Load files, (sub)folders treeview with Windows icons

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: [RESOLVED] If cell not empty...AUTOFILL VBA (FormulaR1C1)

    Probably not the proper way to solve it
    i would have to agree
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width