+ Reply to Thread
Results 1 to 5 of 5

VBA code insert, copy and paste with formula and formats for the Number of rows given as i

  1. #1
    Registered User
    Join Date
    05-26-2021
    Location
    jeddah
    MS-Off Ver
    2016
    Posts
    12

    Question VBA code insert, copy and paste with formula and formats for the Number of rows given as i

    hi all,

    please help me in the below vba code,

    in the work sheet, just want to insert the multiple rows through input box and insert after which row through input box.

    then i make which row to be copied through input box.

    i cannot paste the copied row to which the number of rows are inserted.

    For example, if im inserting 10 rows, after row number 12.
    and copying the row number 9 of selected range as (A9:M9), and paste with formula & Formats to newly inserted rows. (This pasting part code im not getting correct)

    Private Sub CommandButton1_Click()
    Dim iRow As Long
    Dim iCount As Long
    Dim cRow As Long
    Dim i As Long

    iCount = InputBox(Prompt:="How many rows you want to add?")
    iRow = InputBox _
    (Prompt:="After which row you want to add new rows? (Enter the row number")

    For i = 1 To iCount
    Rows(iRow).EntireRow.Insert
    Next i
    cRow = InputBox(Prompt:="Which row you need to copy? (Enter the row number)")

    Rows("AcRow:LcRow").Select
    Selection.Copy
    Application.CutCopyMode = False

    ' this part im not getting properly.
    'Paste formulas and conditional formatting in new row created
    Rows(iRow + iCount).PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone

    End Sub

  2. #2
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: VBA code insert, copy and paste with formula and formats for the Number of rows given

    Try this code:

    Please Login or Register  to view this content.
    Note: Forum rules require you add code tags to posted code (You can do so by highlighting the code and pressing the # in the edit bar)
    Last edited by maniacb; 03-07-2022 at 06:14 PM.

  3. #3
    Registered User
    Join Date
    05-26-2021
    Location
    jeddah
    MS-Off Ver
    2016
    Posts
    12

    Smile Re: VBA code insert, copy and paste with formula and formats for the Number of rows given

    Hello sir,

    thank you for the reply,.

    the code is working that its copy row and paste to all the inserted rows as same coped row.

    but i need to copy the row number and paste with formula and formatting for the inserted rows.

    every time its not going to be the same items in the inserted rows .

    please find the attachment.
    Attached Files Attached Files

  4. #4
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: VBA code insert, copy and paste with formula and formats for the Number of rows given

    Here is an update

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    05-26-2021
    Location
    jeddah
    MS-Off Ver
    2016
    Posts
    12

    Re: VBA code insert, copy and paste with formula and formats for the Number of rows given

    thank you

+ 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. [SOLVED] Code to insert a x number of rows and copy paste values
    By PaulM100 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 07-24-2020, 05:34 AM
  2. VBA code to copy and paste formats only
    By paradocs in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-11-2020, 10:24 PM
  3. Copy/paste number formats only?
    By Dave42 in forum Excel General
    Replies: 4
    Last Post: 01-25-2019, 07:23 AM
  4. [SOLVED] How to copy and paste number formats only?
    By Maestro_J in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 04-12-2017, 05:34 AM
  5. Insert set number of rows between data and copy and paste data above empty rows
    By Orionm45 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-21-2017, 11:35 AM
  6. [SOLVED] VBA code to copy and paste a varying number of Rows
    By sx200n in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-10-2015, 08:57 AM
  7. VBA code to copy cell formats and paste using offset for Rows/Range
    By spenlinhauer in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-12-2014, 07:45 PM

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