Results 1 to 7 of 7

Add a row, copy formulas, and formatting

Threaded View

  1. #1
    Registered User
    Join Date
    01-17-2010
    Location
    Ontario
    MS-Off Ver
    Excel 2007
    Posts
    4

    Unhappy Add a row, copy formulas, and formatting

    I'm new to this forum and new to Excel Macros/VBA and am totally frustrated.

    In my Excel spreadsheet I want to have a button for other users to click that will (1) add a new row in a specific location (right now the code I have will add a new row anywhere the user clicks), (2) copy the formulas (but not the data that has been entered), (3) copy the formatting and (4) number the items in the far left column increasing by 1 each time a new row is added.

    I can find various vba for inserting a new row (but not in a specified spot), I can find how to add numbers by 1 in rows and I have found vba code for copying formatting. But not all in one code so that the 1 action of clicking the button will perform these 4 functions.

    Any help would be so greatly appreciated. Thanks.

    The code for adding the new row that I have (but will insert it where ever the user has clicked) is:
    Sub InsertRow()
        Dim Rng, n As Long, k As Long
        Application.ScreenUpdating = False
        Rng = InputBox("Enter number of rows required.")
        If Rng = "" Then Exit Sub
         Range(ActiveCell, ActiveCell.Offset(Val(Rng) - 1, 0)).EntireRow.Insert
        'need To know how many  formulas To copy down.
        'Assumesfrom A over To last entry In row.
        k = ActiveCell.Offset(-1, 0).Row
        n = Cells(k, 256).End(xlToLeft).Column
        Range(Cells(k, 1), Cells(k + Val(Rng), n)).FillDown
    End Sub
    However, I found this formula in this forum, but it copies the data the user may have input:
    Sub InsertRow(NumRow As Long)
      Dim RowStr As String
      
        RowStr = CStr(Selection.Row) & ":" & NumRow + Selection.Row - 1
        Selection.EntireRow.Copy
        Rows(RowStr).Insert Shift:=xlDown
        Application.CutCopyMode = False
        
    End Sub
    Last edited by Leith Ross; 01-18-2010 at 08:37 PM. Reason: Title was not appropriate/accurate.

Thread Information

Users Browsing this Thread

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

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