PC Review


Reply
Thread Tools Rate Thread

A better Macro for Copying Data

 
 
drinese18
Guest
Posts: n/a
 
      8th Apr 2008
I am trying to create a better macro to copy data from one worksheet to the
next, the thing is, the worksheet I am copying from is not in the same format
as the worksheet I am copying to, therefore the values from worksheet 1 has
to go in different specific cells in worksheet 2, I recorded a macro below
and it works but I know it probably won't work for the other worksheets I
have since the name of the worksheets get changed sometimes, the recorded
macro can be seen below:

Sub Macro1()

Range("D314").Select
Selection.Copy
ChDir "C:\Documents and Settings\jermaine_wanyou\Desktop\FACTBOOK SYSTEM"
Workbooks.Open Filename:= _
"C:\Documents and Settings\jermaine_wanyou\Desktop\FACTBOOK
SYSTEM\Argentina Bucket.xls"
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=True
Range("B7").Select
Application.WindowState = xlMinimized
Windows("Cal.xls").Activate
Range("E3:E14").Select
Application.CutCopyMode = False
Selection.Copy
Windows("Argentina Bucket.xls").Activate
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=True
Range("B8").Select
Windows("Cal.xls").Activate
Range("F3:F14").Select
Application.CutCopyMode = False
Selection.Copy
Windows("Argentina Bucket.xls").Activate
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=True
Range("B11").Select
Windows("Cal.xls").Activate
Range("G3:G14").Select
Application.CutCopyMode = False
Selection.Copy
Windows("Argentina Bucket.xls").Activate
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=True
Range("B12").Select
Windows("Cal.xls").Activate
Range("H3:H14").Select
Application.CutCopyMode = False
Selection.Copy
Windows("Argentina Bucket.xls").Activate
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=True
Range("B16").Select
Windows("Cal.xls").Activate
Range("I3:I14").Select
Application.CutCopyMode = False
Selection.Copy
Windows("Argentina Bucket.xls").Activate
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=True
Range("B13").Select
Windows("Cal.xls").Activate
Range("L3:L14").Select
Application.CutCopyMode = False
Selection.Copy
Windows("Argentina Bucket.xls").Activate
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=True
Range("B17").Select
Windows("Cal.xls").Activate
ActiveWindow.ScrollColumn = 2
ActiveWindow.ScrollColumn = 3
Range("M4:M14").Select
Application.CutCopyMode = False
Selection.Copy
Windows("Argentina Bucket.xls").Activate
Range("C17").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=True
Range("A1").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "Argentina 2007"
Range("A1").Select
ActiveWorkbook.Save
ActiveWindow.Close
Range("H21").Select
End Sub

So I'm just wondering is there anyone who can help me with this
 
Reply With Quote
 
 
 
 
cht13er
Guest
Posts: n/a
 
      8th Apr 2008
On Apr 8, 10:36*am, drinese18 <drines...@discussions.microsoft.com>
wrote:
> I am trying to create a better macro to copy data from one worksheet to the
> next, the thing is, the worksheet I am copying from is not in the same format
> as the worksheet I am copying to, therefore the values from worksheet 1 has
> to go in different specific cells in worksheet 2, I recorded a macro below
> and it works but I know it probably won't work for the other worksheets I
> have since the name of the worksheets get changed sometimes, the recorded
> macro can be seen below:
>
> Sub Macro1()
>
> * * Range("D314").Select
> * * Selection.Copy
> * * ChDir "C:\Documents and Settings\jermaine_wanyou\Desktop\FACTBOOK SYSTEM"
> * * Workbooks.Open Filename:= _
> * * * * "C:\Documents and Settings\jermaine_wanyou\Desktop\FACTBOOK
> SYSTEM\Argentina Bucket.xls"
> * * Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
> SkipBlanks _
> * * * * :=False, Transpose:=True
> * * Range("B7").Select
> * * Application.WindowState = xlMinimized
> * * Windows("Cal.xls").Activate
> * * Range("E3:E14").Select
> * * Application.CutCopyMode = False
> * * Selection.Copy
> * * Windows("Argentina Bucket.xls").Activate
> * * Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
> SkipBlanks _
> * * * * :=False, Transpose:=True
> * * Range("B8").Select
> * * Windows("Cal.xls").Activate
> * * Range("F3:F14").Select
> * * Application.CutCopyMode = False
> * * Selection.Copy
> * * Windows("Argentina Bucket.xls").Activate
> * * Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
> SkipBlanks _
> * * * * :=False, Transpose:=True
> * * Range("B11").Select
> * * Windows("Cal.xls").Activate
> * * Range("G3:G14").Select
> * * Application.CutCopyMode = False
> * * Selection.Copy
> * * Windows("Argentina Bucket.xls").Activate
> * * Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
> SkipBlanks _
> * * * * :=False, Transpose:=True
> * * Range("B12").Select
> * * Windows("Cal.xls").Activate
> * * Range("H3:H14").Select
> * * Application.CutCopyMode = False
> * * Selection.Copy
> * * Windows("Argentina Bucket.xls").Activate
> * * Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
> SkipBlanks _
> * * * * :=False, Transpose:=True
> * * Range("B16").Select
> * * Windows("Cal.xls").Activate
> * * Range("I3:I14").Select
> * * Application.CutCopyMode = False
> * * Selection.Copy
> * * Windows("Argentina Bucket.xls").Activate
> * * Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
> SkipBlanks _
> * * * * :=False, Transpose:=True
> * * Range("B13").Select
> * * Windows("Cal.xls").Activate
> * * Range("L3:L14").Select
> * * Application.CutCopyMode = False
> * * Selection.Copy
> * * Windows("Argentina Bucket.xls").Activate
> * * Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
> SkipBlanks _
> * * * * :=False, Transpose:=True
> * * Range("B17").Select
> * * Windows("Cal.xls").Activate
> * * ActiveWindow.ScrollColumn = 2
> * * ActiveWindow.ScrollColumn = 3
> * * Range("M4:M14").Select
> * * Application.CutCopyMode = False
> * * Selection.Copy
> * * Windows("Argentina Bucket.xls").Activate
> * * Range("C17").Select
> * * Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
> SkipBlanks _
> * * * * :=False, Transpose:=True
> * * Range("A1").Select
> * * Application.CutCopyMode = False
> * * ActiveCell.FormulaR1C1 = "Argentina 2007"
> * * Range("A1").Select
> * * ActiveWorkbook.Save
> * * ActiveWindow.Close
> * * Range("H21").Select
> End Sub
>
> So I'm just wondering is there anyone who can help me with this



You can use
Dim WB1 as Workbook
Dim WB2 as Workbook

Set WB1 = ActiveWorkbook
Set WB2 = Workbooks.Open Filename:= "C:\Documents and Settings
\jermaine_wanyou\Desktop\FACTBOOK SYSTEM\Argentina Bucket.xls"


I thiiiiiiink .. someone else can confirm?

HTH

Chris
 
Reply With Quote
 
gimme_this_gimme_that@yahoo.com
Guest
Posts: n/a
 
      8th Apr 2008
This is a bit off topic. But apt.

It is always more reliable to read a text file and iterate - and store
each line into a Worksheet - than it is to open a Worksheet and copy
and paste data from one Workbook to another.

Reading data makes it so you don't have to copy large amounts of data
into memory which can *really* slow down performance. And I mean so
slow that Excel hangs.

It's also easier to filter out blank lines or bad data.

Also, it's easier to copy data from multiple Workbooks into a single
sheet - because you have a row number that you can increment. The
thing is, with VBA you can execute shift-downarrow to get the last row
- but you might be shift-downarrowing a column that has blanks before
the last line. So you might lose data and not know it.

With the line-at-a-time approach you can create several VBA macros -
each to handle different formats - depending upon the data you're
provided. Sometimes there might be 4 columns - other times 5.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
copying row data through a macro thomas donino Microsoft Excel Programming 4 26th Aug 2009 10:02 AM
Macro for Copying Data clk Microsoft Excel Programming 3 29th Oct 2008 06:19 PM
Copying data with a macro using autofilter =?Utf-8?B?cm1jb21wdXRl?= Microsoft Excel Programming 3 15th Jul 2007 03:50 PM
Macro for copying data =?Utf-8?B?c2phYmxvbnNraQ==?= Microsoft Access Macros 2 29th Jul 2006 05:09 PM
Macro for copying data Roger Bell Microsoft Access 7 20th Nov 2004 04:26 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:17 AM.