ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Problem with copy from one worksheet to another (https://www.excelbanter.com/excel-programming/436469-problem-copy-one-worksheet-another.html)

JayDe

Problem with copy from one worksheet to another
 
I have a problem with copying from one worksheet to another.

First I calculate how many lines that I need to copy, but when do the actual
copy I get an error message.
This is a part from 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


p45cal[_187_]

Problem with copy from one worksheet to another
 

JayDe;565631 Wrote:
'Not working
RappWb.Worksheets("Rapport").Range(Cells(2, 1), Cells(lastline - 1,
8)).Copy
MalWb.Worksheets("Resultat").Cells(7, 1)
End Sub

Try:
With RappWb.Worksheets("Rapport")
Range(.Cells(2, 1), .Cells(lastline - 1, 8)).Copy
MalWb.Worksheets("Resultat").Cells(7, 1)
End With


--
p45cal

*p45cal*
------------------------------------------------------------------------
p45cal's Profile: http://www.thecodecage.com/forumz/member.php?userid=558
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=156125

Microsoft Office Help



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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com