+ Reply to Thread
Results 1 to 4 of 4

How to create Macros buttons to add or delete columns and rows.

  1. #1
    Registered User
    Join Date
    01-05-2014
    Location
    Singapore
    MS-Off Ver
    Excel 2003
    Posts
    13

    How to create Macros buttons to add or delete columns and rows.

    Hi all,

    So I'm trying my hand at creating VBA buttons and functions that do the following.

    Button 1 :
    to add a column with every click. The button will create one extra column. So by design there will be at least 1 column. Example if the button is clicked twice it will create 3 columns. I just need a buffer col. (contains no data)

    Button 2 :
    to delete empty columns leaving only one empty buffer column. That is this button will purge empty columns except the buffer column. OR if ALL the columns are filled, Button2 will create the buffer column.

    Eg. I click Button 1 three times. It creates four columns. I only fill two columns. When Button 2 is clicked it will delete all the empty colums except the buffer column. OR I fill in all four columns, there is no buffer column, when I click Button2 it will insert the buffer col.

    Button 3 :
    to add a row with every click. The button will create one extra row. So by design there will be at least 1 row. Example if the button is clicked twice it will create 3 rows. I just need a buffer row. (contains no data)

    Button 4 :
    to delete empty row leaving only one empty buffer row. That is this button will purge empty row except the buffer row. OR if ALL the columns are filled, Button4 will create the buffer column.

    Eg. I click Button 3 three times. It creates four rows. I only fill two rows. When Button 4 is clicked it will delete all the empty rows except the buffer rows. OR I fill in all four rows, there is no buffer rows, when I click Button4 it will insert the buffer row.

    I'm "learning" VBA coding by trial and error.... mostly frustrating errors... sigh... any help would be good. i have included a sample file that I would like work on.

    In the sample file there are six columns filled with data. The 7th col is empty(the buffer column). The column after that calculates the average of data in filled columns.
    There are eight rows with data and the ninth row is the empty buffer row.

    The "add" buttons must be able copy the format/formula of the column/rows BEFORE the buffer colums/rows and insert it before the buffer column/row.

    I hope I'm clear .... =(

    Thanks.
    Damien
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: How to create Macros buttons to add or delete columns and rows.

    Look at the column and row .delete and .insert. Record macros doing it and review the code, for example i recorded problem 1 and the code is below.

    Columns(6).Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove

    Help (F1) and recording are great for learning VBA.
    Hope this helps

    Sometimes its best to start at the beginning and learn VBA & Excel.

    Please dont ask me to do your work for you, I learnt from Reading books, Recording, F1 and Google and like having all of this knowledge in my head for the next time i wish to do it, or wish to tweak it.
    Available for remote consultancy work PM me

  3. #3
    Registered User
    Join Date
    03-28-2014
    Location
    N. Ireland
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: How to create Macros buttons to add or delete columns and rows.

    Damienchew,

    Is there a purpose for the buffer column? It may be easier to have it removed altogether, then if you wanted to add more information you could just click on the "Add Row" or "Add Column" buttons as required?

    Mowgli

  4. #4
    Registered User
    Join Date
    01-05-2014
    Location
    Singapore
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: How to create Macros buttons to add or delete columns and rows.

    Hi Mowgli,

    Actually there is no purpose for the buffer row or column. I just thought it would be easier to locate an empty row/column, because there is still another column/row that calculates averages.
    But from reading the forum and other sources I realise I could just locate the last used row/column then do an offset, then do an insert... So far I have not been able to do something like that.... I'm totally new at coding... so all errors... =(

    Quote Originally Posted by Mowgli2 View Post
    Damienchew,

    Is there a purpose for the buffer column? It may be easier to have it removed altogether, then if you wanted to add more information you could just click on the "Add Row" or "Add Column" buttons as required?

    Mowgli

+ 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. Create Buttons and Assign Macros for Database
    By madkush in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 11-05-2013, 12:00 AM
  2. delete multiple macros and buttons with one macro
    By sdts in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-18-2012, 04:52 AM
  3. Create Check List to Delete Columns and Create New File
    By margetc in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-26-2011, 05:03 PM
  4. Delete & Create Buttons
    By mcclanat in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-22-2011, 06:34 PM
  5. Macro to delete certain rows and create columns
    By excel77 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-14-2010, 10:06 AM

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