+ Reply to Thread
Results 1 to 5 of 5

Need help for inserting rows & worksheets on button click using VBA

Hybrid View

saket_47 Need help for inserting rows... 10-31-2014, 04:31 AM
natefarm Re: Need help for inserting... 10-31-2014, 05:32 PM
saket_47 Re: Need help for inserting... 11-02-2014, 11:27 PM
natefarm Re: Need help for inserting... 11-03-2014, 11:13 AM
saket_47 Re: Need help for inserting... 11-03-2014, 11:45 PM
  1. #1
    Registered User
    Join Date
    10-31-2014
    Location
    India
    MS-Off Ver
    2007
    Posts
    11

    Need help for inserting rows & worksheets on button click using VBA

    Attached - Workbook_001.xlsm (for reference.)

    Hi, I am novice in VBA application for Excel.
    I need your help in creating VBA (.xlxm) file that will do tasks as detailed below.

    i) The Workbook contains One “Summary” sheet & one “Master” sheet.
    “Summary” sheet has table with Serial number, reference No., Description etc.
    “Master” sheet will be used for making duplicate multiple copies as required.
    ii) On click of a button placed in “Summary” sheet, -
    1. One Row should get added to the table with automatic Next serial number & Next Reference number in series.
    2. After Row is added to the Worksheet, “Master” worksheet should make a copy of itself at the end of all worksheets.
    3. This newly added Worksheet should be renamed to Reference number from Row added in “Summary” sheet
    4. Defined Cells (e.g. A2 or B2 etc) inside this newly added worksheet should reflect values from newly added row in Summary sheet.
    (i.e. Serial Number & Reference Number generated in Summary sheet should also go into Copied Master sheet at specified cells (A2,B2)
    5. After the text is manually entered in “Description” column of “Summary” sheet, it should reflect in respective duplicated “Master” Worksheets at specified cells (C2)
    6. If possible, I want to keep “Master” Sheet hidden.
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor natefarm's Avatar
    Join Date
    04-22-2010
    Location
    Wichita, Kansas
    MS-Off Ver
    2016
    Posts
    1,020

    Re: Need help for inserting rows & worksheets on button click using VBA

    Try this. You'll want to move your Add button up above the data.
    Private Sub Add_Row_And_Worksheet_Click()
    Dim rw As Long, sname As String
    
        Application.ScreenUpdating = False
        rw = Range("B3").End(xlDown).Row + 1
        Rows(rw - 1).Copy
        Rows(rw).PasteSpecial (xlPasteFormats)
        Application.CutCopyMode = False
        Cells(rw, 2).Value = Cells(rw - 1, 2).Value + 1
        sname = "REF" & Format(Right(Cells(rw - 1, 3).Value, Len(Cells(rw - 1, 3).Value) - 3) + 1, "00")
        Cells(rw, 3).Value = sname
    
        With ActiveWorkbook.Sheets("Master")
            .Visible = True
            .Copy after:=Sheets(Sheets.Count)
            .Visible = False
        End With
    
        With ActiveSheet
            .Name = sname
            .Range("A2").Formula = "=Summary!B" & rw
            .Range("B2").Formula = "=Summary!C" & rw
            .Range("C2").Formula = "=Summary!D" & rw
        End With
        Sheets("Summary").Activate
    End Sub
    Acts 4:12
    Salvation is found in no one else, for there is no other name under heaven given to mankind by which we must be saved.

  3. #3
    Registered User
    Join Date
    10-31-2014
    Location
    India
    MS-Off Ver
    2007
    Posts
    11

    Re: Need help for inserting rows & worksheets on button click using VBA

    Dear natefarm,
    Thanks a lot. It worked perfectly as required.

    Is it possible that the button to be positioned at the end of the table & when row is inserted button will also move down by a row.

  4. #4
    Valued Forum Contributor natefarm's Avatar
    Join Date
    04-22-2010
    Location
    Wichita, Kansas
    MS-Off Ver
    2016
    Posts
    1,020

    Re: Need help for inserting rows & worksheets on button click using VBA

    Yes. In the above code, change this:

        Rows(rw - 1).Copy
    to this:

        Rows(rw).Insert
        Rows(rw - 1).Copy

  5. #5
    Registered User
    Join Date
    10-31-2014
    Location
    India
    MS-Off Ver
    2007
    Posts
    11

    Re: Need help for inserting rows & worksheets on button click using VBA

    Thanks again.

+ 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. How to clear contents/delete rows on click of button
    By murchy in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-03-2013, 09:11 AM
  2. Command Button to change the subsequent rows with each click
    By sand_electro in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-12-2012, 04:13 PM
  3. inserting rows with submit button
    By den88 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-03-2010, 06:18 PM
  4. Printing worksheets with a click of a button?
    By ivwshane in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-12-2008, 05:11 AM
  5. copy 45 rows down, repetativly, only on button click?
    By foxgguy2005 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 05-25-2005, 11:06 AM

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