Help with looping a recorded Marco

eelime127

New Member
Joined
Jul 15, 2014
Messages
4
I've recorded a Marco copying and pasting information from one cell to other cells and some of the copying functions paste to two cells. I just need this to loop through all information I'm copying from the the new cells.

Range("I1").Select
Selection.Copy
Range("D1").Select
ActiveSheet.Paste
Range("J1").Select
Application.CutCopyMode = False
Selection.Copy
Range("E1:E2").Select
ActiveSheet.Paste
Range("K1").Select
Application.CutCopyMode = False
Selection.Copy
Range("B1:B2").Select
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
First of all all the Selects don't need to be there

Code:
Range("You didn't show a place").Copy
Range("D1").Paste
Range("J1").Copy
Range("E1:E2").Paste
Range("K1").Copy
Range("B1:B2").Paste

As far as looping, What range are you trying to loop through. We will need additional information to help you out.
 
Upvote 0
You have things copying and pasting from different places to different places. Do you have 486 columns? because the only pattern I'm seeing from the small bit of data you have is I1, J1 and K1. In order to write a loop, there has to be some sort of pattern we can utilize to move through. So here is what we need.

1. What is the range of Data we are looping though (i.e. A1:Z1000)
2. What is the relationship between what is copied and where it should be pasted?
3. What identifier tells us when to paste into 2 cells instead of 1?
 
Upvote 0
[TABLE="width: 500"]
<tbody>[TR]
[TD]XXXXX[/TD]
[TD]12345[/TD]
[TD]6789[/TD]
[/TR]
[TR]
[TD]XXXXX[/TD]
[TD]12345[/TD]
[TD]6789[/TD]
[/TR]
[TR]
[TD]XXXXX[/TD]
[TD]12345[/TD]
[TD]6789[/TD]
[/TR]
[TR]
[TD]XXXXX[/TD]
[TD]12345[/TD]
[TD]6789[/TD]
[/TR]
[TR]
[TD]XXXXX[/TD]
[TD]12345[/TD]
[TD]6789[/TD]
[/TR]
</tbody>[/TABLE]
Here is an example of the data set that has 486 rows of information. This is the data that I need transferred onto an upload document that looks like this:

[TABLE="width: 500"]
<tbody>[TR]
[TD]6789[/TD]
[TD]***[/TD]
[TD]XXXXX[/TD]
[TD]12345[/TD]
[/TR]
[TR]
[TD]6789[/TD]
[TD]***[/TD]
[TD]***[/TD]
[TD]12345[/TD]
[/TR]
</tbody>[/TABLE]

So one row in the first table would equal these two rows. The asterisk is information that repeats so it can be disregarded. But the "6789" and "12345" are the values that need pasted in the range of cells.

Does this help?
 
Upvote 0
I'm still not totally clear as to how to determine which cells need to be pasted twice, or what your range of original data is. Or the format of your new data, is it a new list?
 
Upvote 0
The range of the original data is A1:C484 actually.

[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD="align: center"][/TD]
[TD="align: center"]A[/TD]
[TD="align: center"]B[/TD]
[TD="align: center"]C[/TD]
[TD="align: center"]D[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]6789
[/TD]
[TD]***[/TD]
[TD]XXXXX[/TD]
[TD]12345
[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]6789[/TD]
[TD]***[/TD]
[TD]***[/TD]
[TD]12345[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]


The format of the new document with the copied information is exactly how it is above. It's a document to upload information into a database (the insert statements follow). Red is the information that needs to be copied to a range (A1:A2 and D1:D2) and the purple field is what only needs copied once (C1).

[TABLE="class: cms_table, width: 500"]
<tbody>[TR]
[TD]XXXXX[/TD]
[TD]12345[/TD]
[TD]6789[/TD]
[/TR]
[TR]
[TD]XXXXX[/TD]
[TD]12345[/TD]
[TD]6789[/TD]
[/TR]
[TR]
[TD]XXXXX[/TD]
[TD]12345[/TD]
[TD]6789[/TD]
[/TR]
[TR]
[TD]XXXXX[/TD]
[TD]12345[/TD]
[TD]6789[/TD]
[/TR]
[TR]
[TD]XXXXX[/TD]
[TD]12345[/TD]
[TD]6789[/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0
I think what is still confusing me is that you have 1 row of data repeated and nothing else showing me a pattern, the XXXXX is that the same thing over and over? It NEVER changes? And it only needs to go into C1 for the whoe spreadsheet? If that is the case all you are really trying to do is take A1 Copy to C1 then take Column B Copy it to column D and Column C Copied to Column A. With some infor in Column B. Is that correct?
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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