Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 19
Default Using Closed Workbook as Data Book

My problem is ... everthing opens and saves and closes. What happens is it
does not go to the next line when pasting to the worksheet. It only pastes
any further data to the same row ie. A2:AC2. So I need it to open the closed
workbook copy the source range A2:AC2, paste in the open worksheet to the
NEXT open row. Can someone help me with my code??

Function bIsBookOpen(ByRef szBookName As String) As Boolean
On Error Resume Next
bIsBookOpen = Not (Application.Workbooks(szBookName) Is Nothing)
End Function
Function LastRow(sh As Worksheet)
On Error Resume Next
LastRow = sh.Cells.Find(What:="*", _
After:=sh.Range("A2"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
On Error GoTo 0
End Function
Sub Copy_To_Another_Workbook()
Dim sourceRange As Range
Dim destRange As Range
Dim destWB As Workbook
Dim Lr As Long

Application.ScreenUpdating = False
If bIsBookOpen("Glenns Stats.xls") Then
Set destWB = Workbooks("Glenns Stats.xls")
Else
Set destWB = Workbooks.Open("F:\FILE_CAB\FIREFFTR\Crew
Statistics\Glenns Stats.xls")
End If
Lr = LastRow(destWB.Worksheets("STATS")) + 1
Set sourceRange = ThisWorkbook.Worksheets("STATS").Range("A2:AC2")
Set destRange = destWB.Worksheets("STATS").Range("A" & Lr)
sourceRange.Copy
destRange.PasteSpecial xlPasteValues, , False, False
Application.CutCopyMode = False
destWB.Close True
Application.ScreenUpdating = True
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,123
Default Using Closed Workbook as Data Book

Where do you copy the code ?

In a normal module ?

--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"DarnTootn" wrote in message ...
My problem is ... everthing opens and saves and closes. What happens is it
does not go to the next line when pasting to the worksheet. It only pastes
any further data to the same row ie. A2:AC2. So I need it to open the closed
workbook copy the source range A2:AC2, paste in the open worksheet to the
NEXT open row. Can someone help me with my code??

Function bIsBookOpen(ByRef szBookName As String) As Boolean
On Error Resume Next
bIsBookOpen = Not (Application.Workbooks(szBookName) Is Nothing)
End Function
Function LastRow(sh As Worksheet)
On Error Resume Next
LastRow = sh.Cells.Find(What:="*", _
After:=sh.Range("A2"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
On Error GoTo 0
End Function
Sub Copy_To_Another_Workbook()
Dim sourceRange As Range
Dim destRange As Range
Dim destWB As Workbook
Dim Lr As Long

Application.ScreenUpdating = False
If bIsBookOpen("Glenns Stats.xls") Then
Set destWB = Workbooks("Glenns Stats.xls")
Else
Set destWB = Workbooks.Open("F:\FILE_CAB\FIREFFTR\Crew
Statistics\Glenns Stats.xls")
End If
Lr = LastRow(destWB.Worksheets("STATS")) + 1
Set sourceRange = ThisWorkbook.Worksheets("STATS").Range("A2:AC2")
Set destRange = destWB.Worksheets("STATS").Range("A" & Lr)
sourceRange.Copy
destRange.PasteSpecial xlPasteValues, , False, False
Application.CutCopyMode = False
destWB.Close True
Application.ScreenUpdating = True
End Sub

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 19
Default Using Closed Workbook as Data Book

Yes so far it is in a module, module2, and is run with a cmdClose radio
button on another sheet. Thank you soooo much

"Ron de Bruin" wrote:

Where do you copy the code ?

In a normal module ?

--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"DarnTootn" wrote in message ...
My problem is ... everthing opens and saves and closes. What happens is it
does not go to the next line when pasting to the worksheet. It only pastes
any further data to the same row ie. A2:AC2. So I need it to open the closed
workbook copy the source range A2:AC2, paste in the open worksheet to the
NEXT open row. Can someone help me with my code??

Function bIsBookOpen(ByRef szBookName As String) As Boolean
On Error Resume Next
bIsBookOpen = Not (Application.Workbooks(szBookName) Is Nothing)
End Function
Function LastRow(sh As Worksheet)
On Error Resume Next
LastRow = sh.Cells.Find(What:="*", _
After:=sh.Range("A2"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
On Error GoTo 0
End Function
Sub Copy_To_Another_Workbook()
Dim sourceRange As Range
Dim destRange As Range
Dim destWB As Workbook
Dim Lr As Long

Application.ScreenUpdating = False
If bIsBookOpen("Glenns Stats.xls") Then
Set destWB = Workbooks("Glenns Stats.xls")
Else
Set destWB = Workbooks.Open("F:\FILE_CAB\FIREFFTR\Crew
Statistics\Glenns Stats.xls")
End If
Lr = LastRow(destWB.Worksheets("STATS")) + 1
Set sourceRange = ThisWorkbook.Worksheets("STATS").Range("A2:AC2")
Set destRange = destWB.Worksheets("STATS").Range("A" & Lr)
sourceRange.Copy
destRange.PasteSpecial xlPasteValues, , False, False
Application.CutCopyMode = False
destWB.Close True
Application.ScreenUpdating = True
End Sub


  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,123
Default Using Closed Workbook as Data Book

Are you sure that the sheet is named "STATS"
and not "STATS " with a space or so that you not know ?



--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"DarnTootn" wrote in message ...
Yes so far it is in a module, module2, and is run with a cmdClose radio
button on another sheet. Thank you soooo much

"Ron de Bruin" wrote:

Where do you copy the code ?

In a normal module ?

--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"DarnTootn" wrote in message ...
My problem is ... everthing opens and saves and closes. What happens is it
does not go to the next line when pasting to the worksheet. It only pastes
any further data to the same row ie. A2:AC2. So I need it to open the closed
workbook copy the source range A2:AC2, paste in the open worksheet to the
NEXT open row. Can someone help me with my code??

Function bIsBookOpen(ByRef szBookName As String) As Boolean
On Error Resume Next
bIsBookOpen = Not (Application.Workbooks(szBookName) Is Nothing)
End Function
Function LastRow(sh As Worksheet)
On Error Resume Next
LastRow = sh.Cells.Find(What:="*", _
After:=sh.Range("A2"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
On Error GoTo 0
End Function
Sub Copy_To_Another_Workbook()
Dim sourceRange As Range
Dim destRange As Range
Dim destWB As Workbook
Dim Lr As Long

Application.ScreenUpdating = False
If bIsBookOpen("Glenns Stats.xls") Then
Set destWB = Workbooks("Glenns Stats.xls")
Else
Set destWB = Workbooks.Open("F:\FILE_CAB\FIREFFTR\Crew
Statistics\Glenns Stats.xls")
End If
Lr = LastRow(destWB.Worksheets("STATS")) + 1
Set sourceRange = ThisWorkbook.Worksheets("STATS").Range("A2:AC2")
Set destRange = destWB.Worksheets("STATS").Range("A" & Lr)
sourceRange.Copy
destRange.PasteSpecial xlPasteValues, , False, False
Application.CutCopyMode = False
destWB.Close True
Application.ScreenUpdating = True
End Sub


  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 19
Default Using Closed Workbook as Data Book

No everything is good, I checked.. I copied the code as is in the module.

"Ron de Bruin" wrote:

Are you sure that the sheet is named "STATS"
and not "STATS " with a space or so that you not know ?



--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"DarnTootn" wrote in message ...
Yes so far it is in a module, module2, and is run with a cmdClose radio
button on another sheet. Thank you soooo much

"Ron de Bruin" wrote:

Where do you copy the code ?

In a normal module ?

--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"DarnTootn" wrote in message ...
My problem is ... everthing opens and saves and closes. What happens is it
does not go to the next line when pasting to the worksheet. It only pastes
any further data to the same row ie. A2:AC2. So I need it to open the closed
workbook copy the source range A2:AC2, paste in the open worksheet to the
NEXT open row. Can someone help me with my code??

Function bIsBookOpen(ByRef szBookName As String) As Boolean
On Error Resume Next
bIsBookOpen = Not (Application.Workbooks(szBookName) Is Nothing)
End Function
Function LastRow(sh As Worksheet)
On Error Resume Next
LastRow = sh.Cells.Find(What:="*", _
After:=sh.Range("A2"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
On Error GoTo 0
End Function
Sub Copy_To_Another_Workbook()
Dim sourceRange As Range
Dim destRange As Range
Dim destWB As Workbook
Dim Lr As Long

Application.ScreenUpdating = False
If bIsBookOpen("Glenns Stats.xls") Then
Set destWB = Workbooks("Glenns Stats.xls")
Else
Set destWB = Workbooks.Open("F:\FILE_CAB\FIREFFTR\Crew
Statistics\Glenns Stats.xls")
End If
Lr = LastRow(destWB.Worksheets("STATS")) + 1
Set sourceRange = ThisWorkbook.Worksheets("STATS").Range("A2:AC2")
Set destRange = destWB.Worksheets("STATS").Range("A" & Lr)
sourceRange.Copy
destRange.PasteSpecial xlPasteValues, , False, False
Application.CutCopyMode = False
destWB.Close True
Application.ScreenUpdating = True
End Sub




  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,123
Default Using Closed Workbook as Data Book

Now I see it you changed the function

Use A1 and not A2

Function LastRow(sh As Worksheet)
On Error Resume Next
LastRow = sh.Cells.Find(What:="*", _
After:=sh.Range("A1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
On Error GoTo 0
End Function

Website example is here
http://www.rondebruin.nl/copy1.htm#workbook



--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Ron de Bruin" wrote in message ...
Hi DarnTootn

Send me the workbook you are using now private.
I look at it for you then

--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"DarnTootn" wrote in message ...
No everything is good, I checked.. I copied the code as is in the module.

"Ron de Bruin" wrote:

Are you sure that the sheet is named "STATS"
and not "STATS " with a space or so that you not know ?



--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"DarnTootn" wrote in message ...
Yes so far it is in a module, module2, and is run with a cmdClose radio button on another sheet. Thank you soooo much

"Ron de Bruin" wrote:

Where do you copy the code ?

In a normal module ?

--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"DarnTootn" wrote in message ...
My problem is ... everthing opens and saves and closes. What happens is it does not go to the next line when pasting to
the worksheet. It only pastes any further data to the same row ie. A2:AC2. So I need it to open the closed workbook copy
the source range A2:AC2, paste in the open worksheet to the NEXT open row. Can someone help me with my code??

Function bIsBookOpen(ByRef szBookName As String) As Boolean
On Error Resume Next
bIsBookOpen = Not (Application.Workbooks(szBookName) Is Nothing)
End Function
Function LastRow(sh As Worksheet)
On Error Resume Next
LastRow = sh.Cells.Find(What:="*", _
After:=sh.Range("A2"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
On Error GoTo 0
End Function
Sub Copy_To_Another_Workbook()
Dim sourceRange As Range
Dim destRange As Range
Dim destWB As Workbook
Dim Lr As Long
Application.ScreenUpdating = False
If bIsBookOpen("Glenns Stats.xls") Then
Set destWB = Workbooks("Glenns Stats.xls")
Else
Set destWB = Workbooks.Open("F:\FILE_CAB\FIREFFTR\Crew Statistics\Glenns Stats.xls")
End If
Lr = LastRow(destWB.Worksheets("STATS")) + 1
Set sourceRange = ThisWorkbook.Worksheets("STATS").Range("A2:AC2")
Set destRange = destWB.Worksheets("STATS").Range("A" & Lr)
sourceRange.Copy
destRange.PasteSpecial xlPasteValues, , False, False
Application.CutCopyMode = False
destWB.Close True
Application.ScreenUpdating = True
End Sub



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
Consolidation of data from cell in active sheet of closed workbook Neil X Peel Excel Worksheet Functions 3 March 8th 07 02:35 PM
Data Validation From Closed WorkBook TeRex82 Excel Discussion (Misc queries) 2 May 12th 06 10:45 AM
How to extract data from a wooksheet in a closed workbook kuansheng Excel Worksheet Functions 2 February 15th 06 03:46 AM
Value from a closed workbook Anthony Slater Excel Discussion (Misc queries) 5 May 17th 05 09:49 AM
copy worksheet from closed workbook to active workbook using vba mango Excel Worksheet Functions 6 December 9th 04 07:55 AM


All times are GMT +1. The time now is 06:12 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"