Consulting

Results 1 to 3 of 3

Thread: copy value and insert new row then paste

  1. #1

    copy value and insert new row then paste

    if my Q&i range has value then i need to copy Q&i to T&i value and insert a blank row below the q&i row then paste the copied value to newly inserted row M&i

    i wrote this but shows error
    any one help

    [VBA]Sub main1()
    Dim i As Integer
    For i = 3 To 15
    Range("Q" & i).Select
    If Range("Q" & i).Value <> "" Then
    'ActiveCell.Offset(0, 4).Copy
    ActiveCell.Offset(1, 0).EntireRow.Insert
    ActiveCell.Offset(0, 4).Copy
    Range("M" & i + 1).Select
    active cell.value=""
    'Range.Resize(1, 4).Copy 'Destination:=Worksheets("Master File").Range("M" & .Row + 1)
    End If
    Next i
    i = i + 1
    End Sub[/VBA]
    Last edited by Aussiebear; 06-17-2013 at 10:48 PM. Reason: Added the correct tags to the supplied code

  2. #2
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    what i understand is if Q&i is not blank, insert a blank row after i (which is i + 1) and copy T&i to M&i+1

    [VBA]
    Sub main1()
    Dim i As Integer, LR As Long
    LR = Range("Q" & Rows.Count).End(xlUp).Row
    For i = LR To 3 Step -1
    If Range("Q" & i).Value <> "" Then
    Rows(i + 1).EntireRow.Insert
    Range("T" & i).Copy Range("M" & i + 1)
    End If
    Next i
    End Sub
    [/VBA]
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  3. #3
    VBAX Mentor
    Joined
    Jul 2012
    Posts
    398
    Location
    it's not clear for me what you want but try this code
    [VBA]Sub main2()
    Dim i As Integer
    For i = 15 To 3 Step -1
    Range("Q" & i).Select
    If Range("Q" & i).Value <> "" Then
    'ActiveCell.Offset(0, 4).Copy
    ActiveCell.Offset(1, 0).EntireRow.Insert
    ActiveCell.Offset(0, 4).Copy Range("M" & i + 1)
    'Range.Resize(1, 4).Copy 'Destination:=Worksheets("Master File").Range("M" & .Row + 1)
    End If
    Next i
    End Sub[/VBA]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •