+ Reply to Thread
Results 1 to 9 of 9

Auto Insert Formatted cells below

Hybrid View

  1. #1
    Registered User
    Join Date
    03-24-2011
    Location
    Minneaplois, MN
    MS-Off Ver
    Excel 2007
    Posts
    20

    Auto Insert Formatted cells below

    Hello,

    I am trying to find a way to insert formatted cell below a cell that had a value entered in it. For example, If you set up cell A1 to be a heading with box border, and cell A2 blank with a box border. What I am looking for is to be able to type a 1 in cell A2, and have cell A3 automatically format with a box border.

    I hope that makes sense.
    Attached Files Attached Files

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Auto Insert Formatted cells below

    This event will work if one is entered anywhere in column A.

    Option Explicit
    Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Column = 1 And Target.Value = 1 Then
            Application.EnableEvents = False
    Target.Copy: Target.Offset(1, 0).PasteSpecial xlPasteFormats
    Application.CutCopyMode = False: Application.EnableEvents = True
    End If: End Sub
    If you haven't used macros before you'll need to go to:
    File- options - trust center -trust center settings - macro settings ,
    the second option down (disable all macros with notification)

    Then - Copy the code to the clipboard

    Open your Workbook

    Press ALT + F11 to open the Visual Basic Editor.

    Double Click on Sheet 1 to expose the Sheet Module and

    paste the code under it and

    you're ready to go
    Last edited by xladept; 12-10-2015 at 06:27 PM.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Registered User
    Join Date
    03-24-2011
    Location
    Minneaplois, MN
    MS-Off Ver
    Excel 2007
    Posts
    20

    Re: Auto Insert Formatted cells below

    Hello,

    That works great. Just what I was looking for. One little modification that would be great, which I didn't specify before is, how to make the active cell default to the cell to the left of where the 1 was entered and not the cell that the formatting was made to?

    Thank you.

  4. #4
    Registered User
    Join Date
    03-24-2011
    Location
    Minneaplois, MN
    MS-Off Ver
    Excel 2007
    Posts
    20

    Re: Auto Insert Formatted cells below

    Hello,

    Sorry about the duplicate reply. The modification I am looking for is, how to make the active cell default to the cell to the RIGHT of where the 1 was entered, instead of the cell that the formatting was made to?

    Thank you.

  5. #5
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Auto Insert Formatted cells below

    Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Column = 1 And Target.Value = 1 Then
            Application.EnableEvents = False
    Target.Copy: Target.Offset(1, 0).PasteSpecial xlPasteFormats
                 Target.Offset(0, 1).Select
    Application.CutCopyMode = False: Application.EnableEvents = True
    End If: End Sub

  6. #6
    Registered User
    Join Date
    03-24-2011
    Location
    Minneaplois, MN
    MS-Off Ver
    Excel 2007
    Posts
    20

    Re: Auto Insert Formatted cells below

    Hello,

    Thank you very much. That works. Something I have noticed is that if at sometime i need to delete a row that was auto formatted I get a run time error.

    Is there any way to avoid that?

    Capture.PNG

  7. #7
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Auto Insert Formatted cells below

    Try this:

    Private Sub Worksheet_Change(ByVal Target As Range)
                If Target.Count = 1 Then
    If Target.Column = 1 And Target.Value = 1 Then
            Application.EnableEvents = False
    Target.Copy: Target.Offset(1, 0).PasteSpecial xlPasteFormats
                 Target.Offset(0, 1).Select
    Application.CutCopyMode = False: Application.EnableEvents = True
    End If: End If: End Sub

  8. #8
    Registered User
    Join Date
    03-24-2011
    Location
    Minneaplois, MN
    MS-Off Ver
    Excel 2007
    Posts
    20

    Re: Auto Insert Formatted cells below

    Hello,

    Putting the extra End If: did not work. It now results in the following error without formatting:
    Capture.PNG

  9. #9
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Auto Insert Formatted cells below

    The "extra" End If is to cover this leading code:

    If Target.Count = 1 Then
    Did you include that?

+ 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. AUTO SUM will not work with cells formatted as time
    By Vindauga in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 10-09-2014, 01:22 PM
  2. Auto skip colored cells VBA but include conditionally formatted cells also
    By Cremorneguy in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-31-2014, 03:44 AM
  3. Complex VBA problem auto insert date and time, auto insert comment, etc.
    By rojashan in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-29-2013, 09:40 PM
  4. Replies: 4
    Last Post: 07-03-2012, 06:33 PM
  5. Auto copy formatted cells to new worksheet
    By texas tornado in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-01-2012, 12:36 PM
  6. How-to auto insert quotes in cells
    By drugoholic in forum Excel General
    Replies: 1
    Last Post: 10-03-2009, 04:59 AM
  7. [SOLVED] Converting 'General' formatted cells to Text formatted cell using.
    By Zahid Khan in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-12-2005, 04:06 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