+ Reply to Thread
Results 1 to 2 of 2

Who knows macros??

Hybrid View

Guest Who knows macros?? 03-03-2005, 12:06 AM
Leith Ross Hello Spyder, Here is the... 03-03-2005, 07:45 AM
  1. #1
    Spyder
    Guest

    Who knows macros??

    ..Does anyone know how to write a macro that will allow me to insert a row just
    one row below the row with an "insert row" button on my worksheet. Basically
    what I am trying to accomplish is to have a series of row categories where
    information will be entered. If a user would like to add another line to a
    category for an additional item, I want them to be able to click a button and
    a blank line to be inserted above all the others in the category with the
    same formatting as the other lines in the category. It would be great if
    this was a generic macro that could be used for multiple categories on a
    worksheet when assigned to each categories' separate button.

    EAXAMPLE:

    CATAGORY: CARS [Insert CARS line]
    (After I click the "Insert CARS line" button, a new row with same formatting
    as those below would be inserted here without negatively affecting the
    ability of the "Insert CARS line" to complete the same functionality below.)
    blue car 1999 good condition
    green car 2000 poor condition
    black car 2004 great condition

    CATAGORY: TRUCKS [Insert TRUCKS line]
    green truck 2001 poor condition
    green truck 2001 good condition
    black truck 2004 great condition

    ..THANK YOU VERY MUCH FOR ANY INSIGHT!!!

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259
    Hello Spyder,

    Here is the macro code for the Worksheet Button you have. Copy this into the Click Event and Change "Addx" to the address where the new row is to be inserted.

    Macro Code for Command Button:

    Private Sub CommandButton1_Click()

    'INSERT NEW ROW

    Dim Addx

    'Address where New Row will be Inserted
    Addx = "A10"

    'Insert the New Row with Same Formats and Contents
    With ActiveSheet.Range(Addx).EntireRow
    .Select
    .Copy
    .Insert (xlShiftDown)
    .PasteSpecial (xlAll)
    End With


    'Clear the Contents of the Orignal Row
    ActiveSheet.Range(Addx).EntireRow.ClearContents

    'Set the Active Cell to Addx
    ActiveSheet.Range(Addx).Select

    End Sub

    _________________________________________________________________

    Happy Macroing,
    Leith Ross

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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