Macro for copying individual cells in a column and pasting

zeebo12

New Member
Joined
Jun 12, 2008
Messages
3
Hi,

I'm at a dead end with a macro i've been putting together primarily with hint and code i've picked up of this forum. Essentially i'm putting together a macro to automate the analysis of a report, which will then feed into a mailmerge for communication out to 800 or so contacts.

I am breaking down a spreadsheet for branch managers, based on their branch number - then saving the information in a separate file for the mail merge.

The worksheet i have assembled (Master) feeds off another sheet (Data) and is driven by lookups, utilising the branch code.

The branch codes are stored in a single column (Column A) (800 entries) on a separate sheet (BranchList). For the sake of the macro i copy a branch code and enter it into the lookup cell (G1) on my Master sheet, then save a copy of the master sheet as the branch number, before closing that copied sheet.

So far i have got everything sorted - except how to automate the
repetition of copying of the individual branch codes across from the A cells on BranchList sheet to G1 on the Master sheet.

Code so far is:

Sub TrailOne()
Workbooks.Open Filename:= _
"K:\ATO and Training\Driver Comp\Idling\Idling Reports\MailMerge\we1\BranchList.xls"
Range("A2").Select
Selection.Copy
Windows("444.xls").Activate
Range("G1").Select
ActiveSheet.Paste
Application.Goto Reference:="R1C1"
Cells.Select
Application.CutCopyMode = False
Selection.Copy
Workbooks.Add
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveWorkbook.SaveAs Filename:="\\G\Transport\ATO and Training\Driver Compl\Idling\Idling Reports\MailMerge\we1\" & Range("G1").Value & ".xls"
ActiveWorkbook.Close
End Sub

Any help would be greatly appreciated, and save me having to repeat the code manually 800 times!

Thanks.
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
I'm not exactly sure but it looks like you just want to loop it until there is nothing more in column A. Maybe something like
<CODE>
Dim i as Integer
Dim Lastrow As Integer
With ActiveSheet
LastRow = .Cells(.Rows.count, "A").End(xlUp).Row
End With

For i = 0 To LastRow
Range("A" & i).Select
Selection.Copy
...Put rest of your code here...
Next i
<\CODE>
 
Upvote 0
JasonMac, thanks for the reply.

I am getting a scripting error (1004), specifically focused on the following code:

Range("A" & i).Select

I've tried variations on it without much success, any further guidance would be a massive help
 
Upvote 0
Note that you don't have to select cells to perform actions on them, e.g.

Code:
Range("A2").Select
Selection.Copy
Windows("444.xls").Activate
Range("G1").Select
ActiveSheet.Paste

could be achieved by:
Code:
Range("A2").Copy Workbooks("444.xls").Sheets("Sheet1").Range("G1")

or
Code:
Workbooks("444.xls").Sheets("Sheet1").Range("G1").Value = ThisWorkbook.Sheets("Sheet1").Range("A2")
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,264
Members
449,075
Latest member
staticfluids

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