PC Review


Reply
Thread Tools Rate Thread

Copy from one worksheet to another

 
 
JayDe
Guest
Posts: n/a
 
      21st Nov 2009
I have some code that calculates how many lines I need to copy from one
worksheet to another, but when I do the copy I get an errormessage.

Here is part of my code:


Private Sub Start_Click()

Dim lastline As Integer
Dim MalWb, RappWb As Workbook


Workbooks.OpenText Filename:=RapportFrm.Innfil.Value, Origin:=xlWindows,
StartRow:=1, _
DataType:=xlDelimited, TextQualifier:=xlDoubleQuote,
ConsecutiveDelimiter _
:=False, Tab:=False, Semicolon:=False, Comma:=False, Space:=False, _
Other:=True, OtherChar:="""", FieldInfo:=Array(Array(1, 9), Array(2,
1), _
Array(3, 9), Array(4, 1), Array(5, 9), Array(6, 1), Array(7, 9),
Array(8, 1), Array(9, 9), _
Array(10, 1), Array(11, 9), Array(12, 1), Array(13, 9), Array(14,
1), Array(15, 9)), _
DecimalSeparator:=".", TrailingMinusNumbers:=False

Worksheets(1).Name = "Rapport"

' Some code to calculate lastline


Set RappWb = Workbooks(ActiveWorkbook.Name)

Workbooks.Open RapportFrm.MalFil.Value

Set MalWb = Workbooks(ActiveWorkbook.Name)

'Not working
RappWb.Worksheets("Rapport").Range(Cells(2, 1), Cells(lastline - 1, 8)).Copy
MalWb.Worksheets("Resultat").Cells(7, 1)


End Sub

 
Reply With Quote
 
 
 
 
JLatham
Guest
Posts: n/a
 
      21st Nov 2009
I don't see any code to actually calculate the value for variable 'lastline'.

I'm not sure what column you want to use to get that from, but here's a line
of code that should help:
'existing line of code
Set RappWb = Workbooks(ActiveWorkbook.Name)
'add this right after that line
lastline = RappWb.Worksheets("Rapport").Range("A" & Rows.Count).End(xlUp).Row

that will set lastline to the last row in column A that has a value or
formula in it. Change "A" to whatever column is most appropriate for your
sheet.

"JayDe" wrote:

> I have some code that calculates how many lines I need to copy from one
> worksheet to another, but when I do the copy I get an errormessage.
>
> Here is part of my code:
>
>
> Private Sub Start_Click()
>
> Dim lastline As Integer
> Dim MalWb, RappWb As Workbook
>
>
> Workbooks.OpenText Filename:=RapportFrm.Innfil.Value, Origin:=xlWindows,
> StartRow:=1, _
> DataType:=xlDelimited, TextQualifier:=xlDoubleQuote,
> ConsecutiveDelimiter _
> :=False, Tab:=False, Semicolon:=False, Comma:=False, Space:=False, _
> Other:=True, OtherChar:="""", FieldInfo:=Array(Array(1, 9), Array(2,
> 1), _
> Array(3, 9), Array(4, 1), Array(5, 9), Array(6, 1), Array(7, 9),
> Array(8, 1), Array(9, 9), _
> Array(10, 1), Array(11, 9), Array(12, 1), Array(13, 9), Array(14,
> 1), Array(15, 9)), _
> DecimalSeparator:=".", TrailingMinusNumbers:=False
>
> Worksheets(1).Name = "Rapport"
>
> ' Some code to calculate lastline
>
>
> Set RappWb = Workbooks(ActiveWorkbook.Name)
>
> Workbooks.Open RapportFrm.MalFil.Value
>
> Set MalWb = Workbooks(ActiveWorkbook.Name)
>
> 'Not working
> RappWb.Worksheets("Rapport").Range(Cells(2, 1), Cells(lastline - 1, 8)).Copy
> MalWb.Worksheets("Resultat").Cells(7, 1)
>
>
> End Sub
>

 
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
Sending copy worksheet to mailrecipient - mail adress indicated incell in worksheet Snoopy Microsoft Excel Discussion 1 19th Aug 2009 12:51 PM
Unable to Insert Worksheet/Move and copy worksheet Excel 2003 lukerush Microsoft Excel Worksheet Functions 4 7th Sep 2006 05:05 PM
Unable to Insert Worksheet/Move and copy worksheet Excel 2003 lukerush Microsoft Excel Worksheet Functions 0 7th Sep 2006 03:37 PM
copy range on every worksheet (diff names) to a master worksheet (to be created) Bernie Microsoft Excel Programming 2 22nd Sep 2004 03:30 PM
copy range on every worksheet (diff names) to a master worksheet (to be created) Bernie Microsoft Excel Programming 0 22nd Sep 2004 03:26 PM


Features
 

Advertising
 

Newsgroups
 


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