Excel VBA:Paste multiple times

go2nivas

New Member
Joined
May 27, 2020
Messages
2
Office Version
  1. 2010
  2. 2007
Platform
  1. Windows
Hi All,

I am new to Excel Macro and to this forum. I am trying to write a macro to copy a range multiple times. Please correct me if I am wrong.

Sub Macro1()
Dim x As String
Dim x1 As String
Dim x2 As String

Dim p, q As Integer
Range("A1").Activate

p = 1
q = 1
For i = 1 To 2 Step 1
x2 = Trim(Cells(i, 1).Value)
x = Trim(Cells(i, 2).Value)
p = 1
For j = 1 To c Step 1
q = InStr(p, x)
x1 = Mid(x, p, q - p)
ActiveCell.Value = x2
ActiveCell.Offset(0, 1).Value = x1
ActiveCell.Offset(1, 0).Activate
p = q + 1
Next j

Next i

End Sub

Please see the below-attached image example,

Input

1590580099958.png


Output

1590580278288.png


Thank you in advance.
 

Attachments

  • 1590580238495.png
    1590580238495.png
    14.6 KB · Views: 18

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
How about
VBA Code:
Sub go2nivas()
   Dim Rng As Range
   Dim i As Long, j As Long
   
   j = 1
   Set Rng = Range("B1", Range("B" & Rows.Count).End(xlUp))
   With Range("A1", Range("A" & Rows.Count).End(xlUp))
      .Copy Range("D1").Resize(.Count * Rng.Count)
      For i = 1 To Rng.Count
         .Range("E" & j).Resize(.Count).Value = Rng(i)
         j = j + .Count
      Next i
   End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,967
Members
452,371
Latest member
Frana

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