+ Reply to Thread
Results 1 to 2 of 2

Need help creating specific "add-row" macro using a command button

  1. #1
    Registered User
    Join Date
    03-28-2014
    Location
    Roseville, MI
    MS-Off Ver
    Excel 2007
    Posts
    1

    Need help creating specific "add-row" macro using a command button

    Hi Guys,

    As the title would explain, I am looking for help creating a specialized macro using a command button that would insert rows (IN THE SAME EXACT FORMAT AS THE ROW ABOVE) in my spreadsheet. The tricky part is that there will be several (6) of these command buttons in different parts of the spreadsheet. The trickier part is that each command button that inserts the rows will actually only insert a specific range of cells in a row, instead of the entire row.

    Here is the current VBA code i've been using (The tab is labeled "Expenses"):

    Moderator's note: Please take the time to review our rules. There aren't many, and they are all important. Rule #3 requires code tags. I have added them for you this time because you are a new member. --6StringJazzer

    Please Login or Register  to view this content.

    Initially, I wanted the cells to be inserted at A7 to E7. But, when I used the A7:E7 range in the VBA code, the cells were then inserted at A13 to E13....which I did not want. Therefore, I used the range of A16 to E16 so the cells could be inserted near the end of my data set, which was at A31 to E31. However, I do want the cells to be inserted at A7 to E7.

    There are also 5 more command buttons on my sheet where they will be doing the same task of inserting cells, just in different ranges:

    G8 to AI8
    G22 to AI22
    G33 to AI33
    G44 to AI44
    G55 to AI55


    Again, I want the cells that are inserted by the command button to be the exact same format as the respective row above it.



    Any help I can get is greatly appreciated.

    Thanks in advance.

    Ryan
    Last edited by 6StringJazzer; 03-28-2014 at 09:21 PM.

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Need help creating specific "add-row" macro using a command button

    If you use ActiveCell.Range like this...
    ActiveCell.Range("A16:E16").Insert Shift:=xlDown
    ...the Range is relative to the currently active cell as if the Active cell is cell A1 and the range is 16 rows below. It is not absolutely cells A16:E16

    Use this to insert at row 16
    Range("A16:E16").Insert Shift:=xlDown

    Also, you wouldn't have to select any cell.
    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

+ 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. Adding "Command Button" and "Messages Box" in VBA Macro
    By sanjeevkumarmc in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-09-2014, 07:21 AM
  2. "assign macro" option for a command button not always in menu
    By ajetrumpet in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-15-2013, 04:01 AM
  3. Create a Command Button to "Save As" and "Close" an Excel Workbook
    By thedunna in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 05-26-2013, 05:38 PM
  4. How to change a Command Button caption from "Enable" to "Disable"?
    By Infinity in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-22-2007, 12:14 AM
  5. [SOLVED] set up a command button or macro for open file to "save as"
    By Mo in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-22-2005, 07:19 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