PC Review


Reply
Thread Tools Rate Thread

copy data from source file to w/book

 
 
tkraju via OfficeKB.com
Guest
Posts: n/a
 
      13th Mar 2007
I am looking for code that can do the following task.
I have a downloaded file named "SalesReport.csv" contains source data about
900 rows.Data in the file looks as below.
Col A-----Col B-------Col C---------Col D--------Col E
1 name ----CityCode-- Date ---------UnitsSold-- SaleValue
2.Smith --- MB -------12-Feb-07--- 52 ---- 30052
3.Philips -- BE --------- 12-Feb-07 --- 41 ------ 24065
4.Ravi ---- MB ---------12-Feb-07 ---- 39 ------- 22100
5.Carol ---MB --------12-Feb-07 ----- 50 ------- 28600
I have a w/book contains about 150 w/sheets,all renamed as "SalesReport.csv"
Col A:A names.
Sheet 1 renamed as 'Carol',Sheet2 renamed as "Ravi',Sheet 3 renamed as
"Smith' like this.
Data in the sheet looks as below.
Col A---------Col B ---------Col C
1 Date ---------UnitsSold ---SaleValue
2.10-Feb-07 -- 48 ------- 27645
3.11-Feb-07 --- 47 ------- 27102
My task is If Sheet1 name exists in "SalesReport.csv" Col A:A range and
CityCode=MB,copythat row's data(C:E) and paste these values next to last row
of Sheet1.If Sheet1 name does not exists or CityCode does not matches do
nothing.Loop through all other sheets of W/book and do the same task.
As per my sample data,if I run the maco,Sheet1 name(Carol) exists in Col A:A
of SalesReport.csv
and CityCode is also "MB',so the data values of that row (12-Feb-07,50,28600)
are to be copied and pasted at row 4 in 'Carol' sheet.Then goto next sheet.
I shall be thankful if anybody helps me .

--
Message posted via http://www.officekb.com

 
Reply With Quote
 
 
 
 
=?Utf-8?B?Sm9lbA==?=
Guest
Posts: n/a
 
      13th Mar 2007
I will help. You need two diffferent filenames if both worksheets are opened
at the same time.

One file should be SalesReport.csv and the other SalesmanReport.csv. Let me
know the names of the two files.

"tkraju via OfficeKB.com" wrote:

> I am looking for code that can do the following task.
> I have a downloaded file named "SalesReport.csv" contains source data about
> 900 rows.Data in the file looks as below.
> Col A-----Col B-------Col C---------Col D--------Col E
> 1 name ----CityCode-- Date ---------UnitsSold-- SaleValue
> 2.Smith --- MB -------12-Feb-07--- 52 ---- 30052
> 3.Philips -- BE --------- 12-Feb-07 --- 41 ------ 24065
> 4.Ravi ---- MB ---------12-Feb-07 ---- 39 ------- 22100
> 5.Carol ---MB --------12-Feb-07 ----- 50 ------- 28600
> I have a w/book contains about 150 w/sheets,all renamed as "SalesReport.csv"
> Col A:A names.
> Sheet 1 renamed as 'Carol',Sheet2 renamed as "Ravi',Sheet 3 renamed as
> "Smith' like this.
> Data in the sheet looks as below.
> Col A---------Col B ---------Col C
> 1 Date ---------UnitsSold ---SaleValue
> 2.10-Feb-07 -- 48 ------- 27645
> 3.11-Feb-07 --- 47 ------- 27102
> My task is If Sheet1 name exists in "SalesReport.csv" Col A:A range and
> CityCode=MB,copythat row's data(C:E) and paste these values next to last row
> of Sheet1.If Sheet1 name does not exists or CityCode does not matches do
> nothing.Loop through all other sheets of W/book and do the same task.
> As per my sample data,if I run the maco,Sheet1 name(Carol) exists in Col A:A
> of SalesReport.csv
> and CityCode is also "MB',so the data values of that row (12-Feb-07,50,28600)
> are to be copied and pasted at row 4 in 'Carol' sheet.Then goto next sheet.
> I shall be thankful if anybody helps me .
>
> --
> Message posted via http://www.officekb.com
>
>

 
Reply With Quote
 
=?Utf-8?B?VG9tIE9naWx2eQ==?=
Guest
Posts: n/a
 
      13th Mar 2007
Sub copydata()
Dim sh as Worksheet, sh1 as Worksheet
Dim bk as Workbook, cell as Range
Dim rng1 as Range
set sh = WorkBooks("SalesReport.csv").Worksheets(1)
set rng1 = sh.Range(sh.Cells(2,1),sh.cells(rows.count,1).End(xlup))
set bk = Workbooks("Data.xls")
for each cell in rng1
if cell.offset(0,1).Value = "MB" then
set sh1 = nothing
on Error Resume Next
set sh1 = bk.worksheets(cell.Value)
on Error goto 0
if not sh1 is nothing then
cell.offset(0,2).Resize(1,3).copy _
sh1.cells(rows.count,1).end(xlup)(2)
end if
end if
Next
End Sub

--
Regards,
Tom Ogilvy


"tkraju via OfficeKB.com" wrote:

> I am looking for code that can do the following task.
> I have a downloaded file named "SalesReport.csv" contains source data about
> 900 rows.Data in the file looks as below.
> Col A-----Col B-------Col C---------Col D--------Col E
> 1 name ----CityCode-- Date ---------UnitsSold-- SaleValue
> 2.Smith --- MB -------12-Feb-07--- 52 ---- 30052
> 3.Philips -- BE --------- 12-Feb-07 --- 41 ------ 24065
> 4.Ravi ---- MB ---------12-Feb-07 ---- 39 ------- 22100
> 5.Carol ---MB --------12-Feb-07 ----- 50 ------- 28600
> I have a w/book contains about 150 w/sheets,all renamed as "SalesReport.csv"
> Col A:A names.
> Sheet 1 renamed as 'Carol',Sheet2 renamed as "Ravi',Sheet 3 renamed as
> "Smith' like this.
> Data in the sheet looks as below.
> Col A---------Col B ---------Col C
> 1 Date ---------UnitsSold ---SaleValue
> 2.10-Feb-07 -- 48 ------- 27645
> 3.11-Feb-07 --- 47 ------- 27102
> My task is If Sheet1 name exists in "SalesReport.csv" Col A:A range and
> CityCode=MB,copythat row's data(C:E) and paste these values next to last row
> of Sheet1.If Sheet1 name does not exists or CityCode does not matches do
> nothing.Loop through all other sheets of W/book and do the same task.
> As per my sample data,if I run the maco,Sheet1 name(Carol) exists in Col A:A
> of SalesReport.csv
> and CityCode is also "MB',so the data values of that row (12-Feb-07,50,28600)
> are to be copied and pasted at row 4 in 'Carol' sheet.Then goto next sheet.
> I shall be thankful if anybody helps me .
>
> --
> Message posted via http://www.officekb.com
>
>

 
Reply With Quote
 
=?Utf-8?B?Sm9lbA==?=
Guest
Posts: n/a
 
      13th Mar 2007
Tom: What is the last (2) in the copy statement. I never saw any
documentation on this feature. Is it part of the End or is it part of the
cells?

cell.offset(0,2).Resize(1,3).copy _
sh1.cells(rows.count,1).end(xlup)(2)


"Tom Ogilvy" wrote:

> Sub copydata()
> Dim sh as Worksheet, sh1 as Worksheet
> Dim bk as Workbook, cell as Range
> Dim rng1 as Range
> set sh = WorkBooks("SalesReport.csv").Worksheets(1)
> set rng1 = sh.Range(sh.Cells(2,1),sh.cells(rows.count,1).End(xlup))
> set bk = Workbooks("Data.xls")
> for each cell in rng1
> if cell.offset(0,1).Value = "MB" then
> set sh1 = nothing
> on Error Resume Next
> set sh1 = bk.worksheets(cell.Value)
> on Error goto 0
> if not sh1 is nothing then
> cell.offset(0,2).Resize(1,3).copy _
> sh1.cells(rows.count,1).end(xlup)(2)
> end if
> end if
> Next
> End Sub
>
> --
> Regards,
> Tom Ogilvy
>
>
> "tkraju via OfficeKB.com" wrote:
>
> > I am looking for code that can do the following task.
> > I have a downloaded file named "SalesReport.csv" contains source data about
> > 900 rows.Data in the file looks as below.
> > Col A-----Col B-------Col C---------Col D--------Col E
> > 1 name ----CityCode-- Date ---------UnitsSold-- SaleValue
> > 2.Smith --- MB -------12-Feb-07--- 52 ---- 30052
> > 3.Philips -- BE --------- 12-Feb-07 --- 41 ------ 24065
> > 4.Ravi ---- MB ---------12-Feb-07 ---- 39 ------- 22100
> > 5.Carol ---MB --------12-Feb-07 ----- 50 ------- 28600
> > I have a w/book contains about 150 w/sheets,all renamed as "SalesReport.csv"
> > Col A:A names.
> > Sheet 1 renamed as 'Carol',Sheet2 renamed as "Ravi',Sheet 3 renamed as
> > "Smith' like this.
> > Data in the sheet looks as below.
> > Col A---------Col B ---------Col C
> > 1 Date ---------UnitsSold ---SaleValue
> > 2.10-Feb-07 -- 48 ------- 27645
> > 3.11-Feb-07 --- 47 ------- 27102
> > My task is If Sheet1 name exists in "SalesReport.csv" Col A:A range and
> > CityCode=MB,copythat row's data(C:E) and paste these values next to last row
> > of Sheet1.If Sheet1 name does not exists or CityCode does not matches do
> > nothing.Loop through all other sheets of W/book and do the same task.
> > As per my sample data,if I run the maco,Sheet1 name(Carol) exists in Col A:A
> > of SalesReport.csv
> > and CityCode is also "MB',so the data values of that row (12-Feb-07,50,28600)
> > are to be copied and pasted at row 4 in 'Carol' sheet.Then goto next sheet.
> > I shall be thankful if anybody helps me .
> >
> > --
> > Message posted via http://www.officekb.com
> >
> >

 
Reply With Quote
 
tkraju via OfficeKB.com
Guest
Posts: n/a
 
      13th Mar 2007
Thanks,bou it didn't give me the desired results I need.Your code updated
only sheet1 of my w/book.It has not looped through all sheets of my w/book to
do the same task.My sheet2 and Sheet3 names also exists in "SalesReport.csv"
ColA:A range.Please reread my question carefully.

Tom Ogilvy wrote:
>Sub copydata()
>Dim sh as Worksheet, sh1 as Worksheet
>Dim bk as Workbook, cell as Range
>Dim rng1 as Range
>set sh = WorkBooks("SalesReport.csv").Worksheets(1)
>set rng1 = sh.Range(sh.Cells(2,1),sh.cells(rows.count,1).End(xlup))
>set bk = Workbooks("Data.xls")
>for each cell in rng1
> if cell.offset(0,1).Value = "MB" then
> set sh1 = nothing
> on Error Resume Next
> set sh1 = bk.worksheets(cell.Value)
> on Error goto 0
> if not sh1 is nothing then
> cell.offset(0,2).Resize(1,3).copy _
> sh1.cells(rows.count,1).end(xlup)(2)
> end if
> end if
>Next
>End Sub
>
>> I am looking for code that can do the following task.
>> I have a downloaded file named "SalesReport.csv" contains source data about

>[quoted text clipped - 23 lines]
>> are to be copied and pasted at row 4 in 'Carol' sheet.Then goto next sheet.
>> I shall be thankful if anybody helps me .


--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200703/1

 
Reply With Quote
 
tkraju via OfficeKB.com
Guest
Posts: n/a
 
      13th Mar 2007
I am sorry I didn't checked it properly.Yours code working perfectly.How did
you wrote without using any loop activity.Thak you so much for your help.
Please ignore my last reply.

Tom Ogilvy wrote:
>Sub copydata()
>Dim sh as Worksheet, sh1 as Worksheet
>Dim bk as Workbook, cell as Range
>Dim rng1 as Range
>set sh = WorkBooks("SalesReport.csv").Worksheets(1)
>set rng1 = sh.Range(sh.Cells(2,1),sh.cells(rows.count,1).End(xlup))
>set bk = Workbooks("Data.xls")
>for each cell in rng1
> if cell.offset(0,1).Value = "MB" then
> set sh1 = nothing
> on Error Resume Next
> set sh1 = bk.worksheets(cell.Value)
> on Error goto 0
> if not sh1 is nothing then
> cell.offset(0,2).Resize(1,3).copy _
> sh1.cells(rows.count,1).end(xlup)(2)
> end if
> end if
>Next
>End Sub
>
>> I am looking for code that can do the following task.
>> I have a downloaded file named "SalesReport.csv" contains source data about

>[quoted text clipped - 23 lines]
>> are to be copied and pasted at row 4 in 'Carol' sheet.Then goto next sheet.
>> I shall be thankful if anybody helps me .


--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200703/1

 
Reply With Quote
 
tkraju via OfficeKB.com
Guest
Posts: n/a
 
      14th Mar 2007
Mr.Tom,my sincere thanks to you,the sub working very fine.If I am running
this sub 'N' number of times,it is adding to my w/book sheets 'N' number of
rows with same data.What alteration to this code will prevent this routine
updates my sheets 'N' number of times.I want this routine updates my w/book
sheets only once.If date value of "SalesReport.csv" (col C) exists in any of
my w/book sheets Col A range,the sub prompts a msg."12-Feb-07(date value of
Sales Report) data already exists.Updation not required".I think this date
logic will prevent the sub to run 'N' number of times.

Tom Ogilvy wrote:
>Sub copydata()
>Dim sh as Worksheet, sh1 as Worksheet
>Dim bk as Workbook, cell as Range
>Dim rng1 as Range
>set sh = WorkBooks("SalesReport.csv").Worksheets(1)
>set rng1 = sh.Range(sh.Cells(2,1),sh.cells(rows.count,1).End(xlup))
>set bk = Workbooks("Data.xls")
>for each cell in rng1
> if cell.offset(0,1).Value = "MB" then
> set sh1 = nothing
> on Error Resume Next
> set sh1 = bk.worksheets(cell.Value)
> on Error goto 0
> if not sh1 is nothing then
> cell.offset(0,2).Resize(1,3).copy _
> sh1.cells(rows.count,1).end(xlup)(2)
> end if
> end if
>Next
>End Sub
>
>> I am looking for code that can do the following task.
>> I have a downloaded file named "SalesReport.csv" contains source data about

>[quoted text clipped - 23 lines]
>> are to be copied and pasted at row 4 in 'Carol' sheet.Then goto next sheet.
>> I shall be thankful if anybody helps me .


--
Message posted via http://www.officekb.com

 
Reply With Quote
 
=?Utf-8?B?VFVOR0FOQSBLVVJNQSBSQUpV?=
Guest
Posts: n/a
 
      14th Mar 2007
Mr.Tom,Can you add one more condition - if the date value of "SalesReport"
matches with date value of my w/book sheet ,the sub should end by prompting
msg."12-Feb-07 data already exists.Updation not required".This prevents
repeated updation process.At present If I run the sub n number of times,n
number of times 12-Feb-07 data is being added to last rows of w/book sheets.

"tkraju via OfficeKB.com" wrote:

> Thanks,bou it didn't give me the desired results I need.Your code updated
> only sheet1 of my w/book.It has not looped through all sheets of my w/book to
> do the same task.My sheet2 and Sheet3 names also exists in "SalesReport.csv"
> ColA:A range.Please reread my question carefully.
>
> Tom Ogilvy wrote:
> >Sub copydata()
> >Dim sh as Worksheet, sh1 as Worksheet
> >Dim bk as Workbook, cell as Range
> >Dim rng1 as Range
> >set sh = WorkBooks("SalesReport.csv").Worksheets(1)
> >set rng1 = sh.Range(sh.Cells(2,1),sh.cells(rows.count,1).End(xlup))
> >set bk = Workbooks("Data.xls")
> >for each cell in rng1
> > if cell.offset(0,1).Value = "MB" then
> > set sh1 = nothing
> > on Error Resume Next
> > set sh1 = bk.worksheets(cell.Value)
> > on Error goto 0
> > if not sh1 is nothing then
> > cell.offset(0,2).Resize(1,3).copy _
> > sh1.cells(rows.count,1).end(xlup)(2)
> > end if
> > end if
> >Next
> >End Sub
> >
> >> I am looking for code that can do the following task.
> >> I have a downloaded file named "SalesReport.csv" contains source data about

> >[quoted text clipped - 23 lines]
> >> are to be copied and pasted at row 4 in 'Carol' sheet.Then goto next sheet.
> >> I shall be thankful if anybody helps me .

>
> --
> Message posted via OfficeKB.com
> http://www.officekb.com/Uwe/Forums.a...mming/200703/1
>
>

 
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
Outlook 2002 copy address book to external source tom Microsoft Outlook Form Programming 0 19th Feb 2006 02:11 AM
Importing Selected Source Book Data =?Utf-8?B?R3JleXNvbg==?= Microsoft Excel Misc 3 20th Dec 2005 03:02 PM
Copy data from ODBC data source to new Access table Phil Haddock Microsoft VB .NET 0 19th Apr 2005 08:21 AM
.snp file copy/export - no access to source data Help! Wedgewood Microsoft Access 1 14th Apr 2004 06:40 PM
Chart Source Data Ranges Changing when Data Sheet updated from text file source. Tekn0 Microsoft Excel Charting 3 8th Jan 2004 04:45 PM


Features
 

Advertising
 

Newsgroups
 


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