+ Reply to Thread
Results 1 to 10 of 10

AutoFill Destination but use cell format from cells above

  1. #1
    Registered User
    Join Date
    02-15-2012
    Location
    Indianapolis, USA
    MS-Off Ver
    Excel 2007
    Posts
    9

    AutoFill Destination but use cell format from cells above

    I'm trying to write a macro that will autofill the formula to the left. I also want the values that are autofilled to fit the format of the cells above them. Here is my code:

    Range("D5").Select
    Selection.AutoFill Destination:=Range("D5:D6"), Type:=xlFillSeries
    Range("D5:D6").Select
    Range("F6").Select
    ActiveCell.FormulaR1C1 = "=SUM(R[-3]C:R[-1]C)"
    Range("F6").Select
    Selection.AutoFill Destination:=Range("F6:W6"), Type:=xlFillDefault

    The problem is the initial cell is formatted as a percent. When I use the autofill all the values are formatted as a percent. How can I make the code do what its doing now and then format the cell the similar to the cell above it?
    Last edited by excel0831; 02-21-2012 at 03:14 PM.

  2. #2
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: AutoFill Destination but use cell format from cells above

    You can copy paste number formats.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  3. #3
    Registered User
    Join Date
    02-15-2012
    Location
    Indianapolis, USA
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: AutoFill Destination but use cell format from cells above

    Thanks arlu1201 for responding. How exactly do I do that in VBA?

  4. #4
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: AutoFill Destination but use cell format from cells above

    Please Login or Register  to view this content.

  5. #5
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: AutoFill Destination but use cell format from cells above

    Hi excel8031
    You might try this
    Please Login or Register  to view this content.
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  6. #6
    Registered User
    Join Date
    02-15-2012
    Location
    Indianapolis, USA
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: AutoFill Destination but use cell format from cells above

    I'm trying to copy the format of the cell's not the values. The code arlu1201 you provided copies cells, which includes the values erasing the values I autofilled with my formula.

  7. #7
    Registered User
    Join Date
    02-15-2012
    Location
    Indianapolis, USA
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: AutoFill Destination but use cell format from cells above

    Jaslake thank you for your response this does work. My only issue is that some of the columns within F:W are formatted as a percent and I want to keep them formatted as a percent. Is there any way instead of using copy to have the cells mimic the same format as cells in the row above?

  8. #8
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: AutoFill Destination but use cell format from cells above

    Hi excel8031
    I have a difficult time visualizing what you're trying to accomplish. From the code you presented, see if this does as you require.
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    02-15-2012
    Location
    Indianapolis, USA
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: AutoFill Destination but use cell format from cells above

    Yes! That worked! Thank you so much!

  10. #10
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: AutoFill Destination but use cell format from cells above

    Hi excel8031

    You're welcome...glad I could be of help. If that satisfies your need, I'd appreciate it if you'll please mark your thread as "Solved".

    To mark your thread solved do the following:
    - Go to your first post on the thread
    - Click edit
    - Click Advance
    - Just below the word "Title:" you will see a dropdown with the word No prefix.
    - Change to Solved
    - Click Save

+ 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