Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Error 91
Variable or object or block not def...in line: destcell = sh1.Cells(Rows.Count, 1).End(xlUp)(1) |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
transfering data in another column entering more sorted data | Excel Worksheet Functions | |||
how do i change the print settings for an entire wbook in excel? | Setting up and Configuration of Excel | |||
Transfering data across worksheets | Excel Discussion (Misc queries) | |||
transfering data value from 2 Wbook... | Excel Programming | |||
Read And Write On A Closed Wbook | Excel Programming |