PC Review


Reply
Thread Tools Rate Thread

copying cells from one file to another file

 
 
oercim
Guest
Posts: n/a
 
      10th Aug 2009
Hello. I need help. I am not a profession VBA programmer. I want to
create macro such that it will copy some cells from a file(let C:
\folder\file1) to other filelet C:\folder\file2).

The below macro isnot my main macro. However if it works, I can make
work may main macro. But the below one doesnt work, with same style
how can I make it work? Thanks alot

I try to copy "cell(1,1) of Sheet1 of C:\folder\file1" to "cell
(1,1) of Sheet1 of C:\folder\file2"

Sub macro1()
F1 = "C:\folder\file1"
F2 = "C:\folder\file2"
F2.Sheets("Sheet1").Cells(1,1) = F1.Sheets("Sheet1").Cells(1,1)
End Sub
 
Reply With Quote
 
 
 
 
Joel
Guest
Posts: n/a
 
      10th Aug 2009
Try these changes

Sub CopyCells()
F1Name = "C:\folder\file1"
F2Name = "C:\folder\file2"

Set F1 = Workbooks.Open(Filename:=F1Name)
Set F2 = Workbooks.Open(Filename:=F2Name)

'this will not copy any formating
F2.Sheets("Sheet1").Cells(1, 1) = F1.Sheets("Sheet1").Cells(1, 1)
'this will copy formating
F1.Sheets("Sheet1").Cells(1, 1).Copy _
Destination:=F2.Sheets("Sheet1").Cells(1, 1)

'or copy multiple cells
F1.Sheets("Sheet1").Range("A1:B10").Copy _
Destination:=F2.Sheets("Sheet1").Cells(1, 1)

End Sub



"oercim" wrote:

> Hello. I need help. I am not a profession VBA programmer. I want to
> create macro such that it will copy some cells from a file(let C:
> \folder\file1) to other filelet C:\folder\file2).
>
> The below macro isnot my main macro. However if it works, I can make
> work may main macro. But the below one doesnt work, with same style
> how can I make it work? Thanks alot
>
> I try to copy "cell(1,1) of Sheet1 of C:\folder\file1" to "cell
> (1,1) of Sheet1 of C:\folder\file2"
>
> Sub macro1()
> F1 = "C:\folder\file1"
> F2 = "C:\folder\file2"
> F2.Sheets("Sheet1").Cells(1,1) = F1.Sheets("Sheet1").Cells(1,1)
> End Sub
>

 
Reply With Quote
 
oercim
Guest
Posts: n/a
 
      10th Aug 2009
On 10 AÄŸustos, 13:18, Joel <J...@discussions.microsoft.com> wrote:
> Try these changes
>
> Sub CopyCells()
> F1Name = "C:\folder\file1"
> F2Name = "C:\folder\file2"
>
> Set F1 = Workbooks.Open(Filename:=F1Name)
> Set F2 = Workbooks.Open(Filename:=F2Name)
>
> 'this will not copy any formating
> F2.Sheets("Sheet1").Cells(1, 1) = F1.Sheets("Sheet1").Cells(1, 1)
> 'this will copy formating
> F1.Sheets("Sheet1").Cells(1, 1).Copy _
> Â* Â*Destination:=F2.Sheets("Sheet1").Cells(1, 1)
>
> 'or copy multiple cells
> F1.Sheets("Sheet1").Range("A1:B10").Copy _
> Â* Â*Destination:=F2.Sheets("Sheet1").Cells(1, 1)
>
> End Sub
>
>
>
> "oercim" wrote:
> > Hello. I need help. I am not a profession VBA programmer. I want to
> > create macro such that it will copy some cells from a file(let C:
> > \folder\file1) to other filelet C:\folder\file2).

>
> > The below macro Â*isnot my main macro. However if it works, I can make
> > work may main macro. But the below one doesnt work, Â*with same style
> > how can I Â*make it work? Thanks alot

>
> > I try to copy Â*"cell(1,1) of Sheet1 of C:\folder\file1" Â*to Â*"cell
> > (1,1) of Sheet1 of C:\folder\file2"

>
> > Sub macro1()
> > F1 = "C:\folder\file1"
> > F2 = "C:\folder\file2"
> > F2.Sheets("Sheet1").Cells(1,1) = F1.Sheets("Sheet1").Cells(1,1)
> > End Sub


I just want to copy values not the format or other things when I use
my way in the same file copying from one sheet to another it works.
For example

Sub macro1()
Sheets("Sheet2").Cells(1,1) = Sheets("Sheet1").Cells(1,1)
End Sub

Above one works fine fcopying cell(1,1) from Sheet1 to Sheet2. Cant I
use use this type in copying from one file to anotjer file? thanks
alot




 
Reply With Quote
 
oercim
Guest
Posts: n/a
 
      10th Aug 2009
On 10 AÄŸustos, 13:18, Joel <J...@discussions.microsoft.com> wrote:
> Try these changes
>
> Sub CopyCells()
> F1Name = "C:\folder\file1"
> F2Name = "C:\folder\file2"
>
> Set F1 = Workbooks.Open(Filename:=F1Name)
> Set F2 = Workbooks.Open(Filename:=F2Name)
>
> 'this will not copy any formating
> F2.Sheets("Sheet1").Cells(1, 1) = F1.Sheets("Sheet1").Cells(1, 1)
> 'this will copy formating
> F1.Sheets("Sheet1").Cells(1, 1).Copy _
> Â* Â*Destination:=F2.Sheets("Sheet1").Cells(1, 1)
>
> 'or copy multiple cells
> F1.Sheets("Sheet1").Range("A1:B10").Copy _
> Â* Â*Destination:=F2.Sheets("Sheet1").Cells(1, 1)
>
> End Sub
>
>
>
> "oercim" wrote:
> > Hello. I need help. I am not a profession VBA programmer. I want to
> > create macro such that it will copy some cells from a file(let C:
> > \folder\file1) to other filelet C:\folder\file2).

>
> > The below macro Â*isnot my main macro. However if it works, I can make
> > work may main macro. But the below one doesnt work, Â*with same style
> > how can I Â*make it work? Thanks alot

>
> > I try to copy Â*"cell(1,1) of Sheet1 of C:\folder\file1" Â*to Â*"cell
> > (1,1) of Sheet1 of C:\folder\file2"

>
> > Sub macro1()
> > F1 = "C:\folder\file1"
> > F2 = "C:\folder\file2"
> > F2.Sheets("Sheet1").Cells(1,1) = F1.Sheets("Sheet1").Cells(1,1)
> > End Sub


Thanks alot. I did it. Again thanks alot. That was very helpful for me
 
Reply With Quote
 
Joel
Guest
Posts: n/a
 
      10th Aug 2009
Sorry to confuse you. I just gave additional methods for copying. The only
problem with you code is the refereencing the other workbook. I assumed the
workbooks were closed. I just realized the workbooks may be opened. Here is
code assuming the workbooks were opened.

Sub CopyCells()
F1Name = "C:\folder\file1"
F2Name = "C:\folder\file2"

Set F1 = Workbooks(F1Name)
Set F2 = Workbooks(F2Name)

'this will not copy any formating
F2.Sheets("Sheet1").Cells(1, 1) = F1.Sheets("Sheet1").Cells(1, 1)
'this will copy formating
F1.Sheets("Sheet1").Cells(1, 1).Copy _
Destination:=F2.Sheets("Sheet1").Cells(1, 1)

'or copy multiple cells
F1.Sheets("Sheet1").Range("A1:B10").Copy _
Destination:=F2.Sheets("Sheet1").Cells(1, 1)

End Sub



"oercim" wrote:

> On 10 AÄŸustos, 13:18, Joel <J...@discussions.microsoft.com> wrote:
> > Try these changes
> >
> > Sub CopyCells()
> > F1Name = "C:\folder\file1"
> > F2Name = "C:\folder\file2"
> >
> > Set F1 = Workbooks.Open(Filename:=F1Name)
> > Set F2 = Workbooks.Open(Filename:=F2Name)
> >
> > 'this will not copy any formating
> > F2.Sheets("Sheet1").Cells(1, 1) = F1.Sheets("Sheet1").Cells(1, 1)
> > 'this will copy formating
> > F1.Sheets("Sheet1").Cells(1, 1).Copy _
> > Destination:=F2.Sheets("Sheet1").Cells(1, 1)
> >
> > 'or copy multiple cells
> > F1.Sheets("Sheet1").Range("A1:B10").Copy _
> > Destination:=F2.Sheets("Sheet1").Cells(1, 1)
> >
> > End Sub
> >
> >
> >
> > "oercim" wrote:
> > > Hello. I need help. I am not a profession VBA programmer. I want to
> > > create macro such that it will copy some cells from a file(let C:
> > > \folder\file1) to other filelet C:\folder\file2).

> >
> > > The below macro isnot my main macro. However if it works, I can make
> > > work may main macro. But the below one doesnt work, with same style
> > > how can I make it work? Thanks alot

> >
> > > I try to copy "cell(1,1) of Sheet1 of C:\folder\file1" to "cell
> > > (1,1) of Sheet1 of C:\folder\file2"

> >
> > > Sub macro1()
> > > F1 = "C:\folder\file1"
> > > F2 = "C:\folder\file2"
> > > F2.Sheets("Sheet1").Cells(1,1) = F1.Sheets("Sheet1").Cells(1,1)
> > > End Sub

>
> I just want to copy values not the format or other things when I use
> my way in the same file copying from one sheet to another it works.
> For example
>
> Sub macro1()
> Sheets("Sheet2").Cells(1,1) = Sheets("Sheet1").Cells(1,1)
> End Sub
>
> Above one works fine fcopying cell(1,1) from Sheet1 to Sheet2. Cant I
> use use this type in copying from one file to anotjer file? thanks
> alot
>
>
>
>
>

 
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
Error Copying File or Folder message when copying file to CD MichaelRLanier@gmail.com Microsoft Excel Programming 0 2nd Aug 2008 05:43 PM
OVERLY-LONG FILE NAMES, as impediment to file copying =?Utf-8?B?RXZlcnltYW5FbmRVc2Vy?= Windows XP Help 6 17th Aug 2005 03:14 AM
Copying Pivot Table to new file--why does it still refer to original file? LJones Microsoft Excel Misc 1 1st Aug 2004 09:26 PM
Copying File Security Attributes From One File System Tree To Another? CHANGE USERNAME TO westes Microsoft Windows 2000 Security 1 21st Jul 2004 01:28 AM
RE: Error Copying File or Folder - Access denied - The source file may be in use diasmith [MSFT] Microsoft Windows 2000 Security 0 30th Oct 2003 08:41 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:46 AM.