Copy data and paste it into multiple rows, not a single row (vba)

ewuchatka

New Member
Joined
Nov 23, 2016
Messages
11
The code below copies data (Associate Entry named range) and pastes it into the particular row number (1RecRow) in a different sheet (AssociateData).

I would like the row to be pasted to all the rows ONLY BELOW the numbered row.
There are a couple of things to bear in mind:

A. The data is filtered and I would like the pasting to affect rows below "1 RecRow" within the filtered view (not ALL - unfiltered - data).
B. If it helps, the data is sorted in a way if the "1 RecRow" is 23, then the next row is 24, 25, 26, 27 (in order).

So manually I would do it in this way: Paste the data in the particular row, copy the data again from 1 RecRow, Ctrl+Shift+Down arrow and Paste. I'm just not sure how to adjust the code so that it performs it.

Code:
Sub UpdateLogRecord()

    Dim historyWks As Worksheet
    Dim inputWks As Worksheet

    Dim lRec As Long
    Dim oCol As Long
    Dim lRecRow As Long

    Dim myCopy As Range
    Dim myTest As Range

    Dim lRsp As Long

    Set inputWks = Worksheets("Input")
    Set historyWks = Worksheets("AssociateData")
    oCol = 3 'associate info is pasted on data sheet, starting in this column

    'check for duplicate order ID in database
    If inputWks.Range("CheckAssNo") = False Then
      lRsp = MsgBox("Order ID not in database. Add record?", vbQuestion + vbYesNo, "New Order ID")
      If lRsp = vbYes Then
        UpdateLogWorksheet
      Else
        MsgBox "Please select Order ID that is in the database."
      End If

    Else

      'cells to copy from Input sheet - some contain formulas
      Set myCopy = inputWks.Range("AssociateEntry")

      lRec = inputWks.Range("CurrRec").Value
      lRecRow = lRec + 1

      With inputWks
          Set myTest = myCopy.Offset(0, 2)

          If Application.Count(myTest) > 0 Then
              MsgBox "Please fill in all the cells!"
              Exit Sub
          End If
      End With


      With historyWks
          With .Cells(lRecRow, "A")
              .Value = Now
              .NumberFormat = "mm/dd/yyyy hh:mm:ss"
          End With
          .Cells(lRecRow, "B").Value = Application.UserName

          myCopy.Copy
          .Cells(lRecRow, 3).PasteSpecial Paste:=xlPasteValues, Transpose:=True
          Application.CutCopyMode = False
      End With      

      'clear input cells that contain constants
      ClearDataEntry
  End If

End Sub

Thanks
E
 
Last edited:

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!

Forum statistics

Threads
1,216,591
Messages
6,131,629
Members
449,658
Latest member
JasonEncon

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top