transfering data from a one workbook to another workbook

  • Thread starter David Shoemaker
  • Start date
D

David Shoemaker

I have a workbook that i enter data into, and i want to take certain data in
that workbook and transfer it to another workbook with a pivot table so i can
use it like a data base so i can search or orders
 
G

Gary Brown

Creae a pivot table in the second workbook that references the data in the
firs workbook.
 
D

David Shoemaker

It is giving me a compile error saying (sub or function not defined)

Sub Copy_To_Another_Workbook()

Lr = LastRow(DestSh)
 
D

David Shoemaker

I copied straight from your web site, can you send me an example because I
still cant get it to work

Thanks for all your help
 
R

Ron de Bruin

It is very easy

If you want to test the first code example

Sub copy_1()
Dim SourceRange As Range, DestRange As Range
Dim DestSheet As Worksheet, Lr As Long

With Application
.ScreenUpdating = False
.EnableEvents = False
End With

'fill in the Source Sheet and range
Set SourceRange = Sheets("Sheet1").Range("A1:K1")

'Fill in the destination sheet and call the LastRow
'function to find the last row
Set DestSheet = Sheets("Sheet2")
Lr = LastRow(DestSheet)

'With the information from the LastRow function we can
'create a destination cell and copy/paste the source range
Set DestRange = DestSheet.Range("A" & Lr + 1)
SourceRange.Copy DestRange

With Application
.ScreenUpdating = True
.EnableEvents = True
End With

End Sub


You must also copy this function from my page

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top