Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default transfering data from 2 wbook

I have 2 Wbook LISTA_2005 and LISTA_2004.
Into all 2 Wbook are present many sheets named with the alphabetical
letter A, B, C.... ecc.

All sheets A, B, C ... ecc, contain the first 2 line with header (range
A to V).
From the 3th line are present many value from range A to V.

I would want to transfer the data sheets from LISTA_2004 to data sheets
LISTA_2005 in this mode:

All line (A3 to V....) from the sheet named A into LISTA_2004 into
LISTA_2005 into shest A
All line (A3 to V....) from the sheet named B into LISTA_2004 into
LISTA_2005 into shest B
ecc...

Naturally if into destination sheets are present already a value add
into bottom of this the source line from LISTA_2005...

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default transfering data from 2 wbook

Assume both workbooks are open.

Sub copydata()
Dim bk1 As Workbook, bk2 As Workbook
Dim sh As Worksheet, sh1 As Worksheet
Dim lastrow As Long
Dim destcell As Range
Set bk1 = Workbooks("LISTA_2004")
Set bk2 = Workbooks("LISTA_2005")
For Each sh In bk1.Worksheets
Set sh1 = Nothing
On Error Resume Next
Set sh1 = bk2.Worksheets(sh.Name)
On Error GoTo 0
If sh1 Is Nothing Then
Set sh1 = bk2.Worksheets.Add(After:= _
bk2.Worksheets(bk2.Worksheets.Count))
sh1.Name = sh.Name
sh.UsedRange.Copy Destination:=sh1.Range("A1")
Else
lastrow = sh.Cells(Rows.Count, 1).End(xlUp).Row + 1
destcell = sh1.Cells(Rows.Count, 1).End(xlUp)(1)
sh.Range(sh.Cells(3, 1), sh.Cells(lastrow, "V")).Copy _
Destination:=destcell
End If
Next
End Sub


Untested, but this should be very close.
--
Regards,
Tom Ogilvy


"sal21" wrote in message
ups.com...
I have 2 Wbook LISTA_2005 and LISTA_2004.
Into all 2 Wbook are present many sheets named with the alphabetical
letter A, B, C.... ecc.

All sheets A, B, C ... ecc, contain the first 2 line with header (range
A to V).
From the 3th line are present many value from range A to V.

I would want to transfer the data sheets from LISTA_2004 to data sheets
LISTA_2005 in this mode:

All line (A3 to V....) from the sheet named A into LISTA_2004 into
LISTA_2005 into shest A
All line (A3 to V....) from the sheet named B into LISTA_2004 into
LISTA_2005 into shest B
ecc...

Naturally if into destination sheets are present already a value add
into bottom of this the source line from LISTA_2005...



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default transfering data from 2 wbook

Error 91
Variable or object or block not def...in line:
destcell = sh1.Cells(Rows.Count, 1).End(xlUp)(1)

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default transfering data from 2 wbook

Sub copydata()
Dim bk1 As Workbook, bk2 As Workbook
Dim sh As Worksheet, sh1 As Worksheet
Dim lastrow As Long
Dim destcell As Range
Set bk1 = Workbooks("LISTA_2004")
Set bk2 = Workbooks("LISTA_2005")
For Each sh In bk1.Worksheets
Set sh1 = Nothing
On Error Resume Next
Set sh1 = bk2.Worksheets(sh.Name)
On Error GoTo 0
If sh1 Is Nothing Then
Set sh1 = bk2.Worksheets.Add(After:= _
bk2.Worksheets(bk2.Worksheets.Count))
sh1.Name = sh.Name
sh.UsedRange.Copy Destination:=sh1.Range("A1")
Else
lastrow = sh.Cells(Rows.Count, 1).End(xlUp).Row + 1
set destcell = sh1.Cells(Rows.Count, 1).End(xlUp)(1)
sh.Range(sh.Cells(3, 1), sh.Cells(lastrow, "V")).Copy _
Destination:=destcell
End If
Next
End Sub

--
Regards,
Tom Ogilvy


"sal21" wrote in message
ups.com...
Error 91
Variable or object or block not def...in line:
destcell = sh1.Cells(Rows.Count, 1).End(xlUp)(1)



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default transfering data from 2 wbook

Tom, your code work perfect! Tks.
PIzza for you.(i live in Napoli - Italy)

A little modify...
Into column G of each sheet (LISTA_204 and LISTA_2005) is prsent a
unique id identify with a number.
Well, if a line (identifyed with ID of column G) of sheet A into
LISTA_2004 is alreday present into sheet A of LISTA_2005 not transfer
thi line and aborate the nex line...ecc...

In this mode i can controll if a user run, for error, the same macro an
make a dupes of line...
Sorry for my english but i hope you have understand me..



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default transfering data from 2 wbook

I caste testID as String. If it is a number, caste/dim it as Long

Sub copydata()
Dim bk1 As Workbook, bk2 As Workbook
Dim sh As Worksheet, sh1 As Worksheet
Dim lastrow As Long
Dim destcell As Range
Dim testId as String, res as Variant
Set bk1 = Workbooks("LISTA_2004")
Set bk2 = Workbooks("LISTA_2005")
For Each sh In bk1.Worksheets
Set sh1 = Nothing
On Error Resume Next
Set sh1 = bk2.Worksheets(sh.Name)
On Error GoTo 0
If sh1 Is Nothing Then
Set sh1 = bk2.Worksheets.Add(After:= _
bk2.Worksheets(bk2.Worksheets.Count))
sh1.Name = sh.Name
sh.UsedRange.Copy Destination:=sh1.Range("A1")
Else
lastrow = sh.Cells(Rows.Count, 1).End(xlUp).Row + 1
testId = sh.Cells(lastrow - 1,"G").Value
set destcell = sh1.Cells(Rows.Count, 1).End(xlUp)(1)
if sh.index = 1 then
res = Application.Match(testId,sh1.Columns(7),0)
if not iserror(res) then
msgbox "This macro has already been run - quitting . . . "
exit sub
End if
End if
sh.Range(sh.Cells(3, 1), sh.Cells(lastrow, "V")).Copy _
Destination:=destcell
End If
Next
End Sub


--
Regards,
Tom Ogilvy

"sal21" wrote in message
oups.com...
Tom, your code work perfect! Tks.
PIzza for you.(i live in Napoli - Italy)

A little modify...
Into column G of each sheet (LISTA_204 and LISTA_2005) is prsent a
unique id identify with a number.
Well, if a line (identifyed with ID of column G) of sheet A into
LISTA_2004 is alreday present into sheet A of LISTA_2005 not transfer
thi line and aborate the nex line...ecc...

In this mode i can controll if a user run, for error, the same macro an
make a dupes of line...
Sorry for my english but i hope you have understand me..



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
transfering data in another column entering more sorted data Kevin - Corporate Services Excel Worksheet Functions 0 August 6th 08 09:23 PM
how do i change the print settings for an entire wbook in excel? energizerw1 Setting up and Configuration of Excel 2 October 25th 06 12:55 AM
Transfering data across worksheets GarToms Excel Discussion (Misc queries) 2 March 7th 06 01:31 PM
transfering data value from 2 Wbook... sal21[_68_] Excel Programming 0 August 25th 05 09:26 PM
Read And Write On A Closed Wbook sal21[_47_] Excel Programming 2 November 11th 04 11:10 PM


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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"