View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
K.K.[_2_] K.K.[_2_] is offline
external usenet poster
 
Posts: 8
Default How to copy entire row fm an xls file to another xls file?

Hi All & Cool

Thanks for your reply, I'm now trying your code but I don't have much
experience with excel - VB so I got a few probelm(hopefully easy one)...

Acutally what I'm want to do is go thru each record and validate them, if
the record failed then I want to copy it into a "Pending" excel file.

Now my problem become how to go thru each used row in the file?

Cool, after I got your code, I implement it but got an "Subscript out of
range" error (in "*" below)
Dim XlsApp(1 To 2) As Excel.Application
Dim WkBk(1 To 2) As Excel.Workbook
Dim WkSh(1 To 2) As Excel.Worksheet
Dim Range(1 To 2) As Excel.Range
Dim iRow As Integer


lblReturnedStatus.Caption = "Initialising Excel connection..."
lblReturnedStatus.Refresh
sErr = ""
funCheck = True

Set XlsApp(1) = New Excel.Application
Set XlsApp(2) = New Excel.Application
XlsApp(1).Visible = False
XlsApp(2).Visible = False
Set WkBk(1) = XlsApp(1).Workbooks.Open(pFilePath & pFileName)
Set WkBk(2) =
XlsApp(2).Workbooks.Open("P:\Optimum\Data\Returned \UnMatchedRecords\NAC.xls"
)
Set WkSh(1) = Workbooks(1).Worksheets(1)
Set WkSh(2) = Workbooks(2).Worksheets(2) '* * * error here * * *
Set Range(1) = WkSh(1).UsedRange
Set Range(2) = WkSh(2).UsedRange
WkSh(1).Rows(13).Copy WkSh(2).Rows(15)

For iRow = 1 To Range(1).Row
MsgBox WkSh(1).Cells(iRow, "C")
Next

XlsApp(1).Quit
XlsApp(2).Quit
Set WkSh(1) = Nothing
Set WkSh(2) = Nothing

"keepITcool" wrote in message
...

if it's just excel data you're transferring i'd never
use ado but stick to 'pure' excel.

(probably faster
easier coding
less overhead
and less chance of memory leaking and strange lockups)



dim ws(1 to 2) as excel.worksheet
dim rg(1 to 2) as excel.range
set ws(1)=workbooks(1).worksheets(1)
set ws(2)=workbooks(2).worksheets(5)

ws(1).rows(13).copy ws(2).rows(15)

'or

ws(1).cells(123,18).entirerow.copy _
destination:=ws(2).cells(2^16,1).end(xlup).offset( 1).entirerow

'if you use .entirerow it doesn't matter in which column you 'start'



although 'generalized' that would work for me :)



keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


"K.K." wrote:

Hi All,

I have an app in VB6 that will open an excel file, validate then
process the data, if the validation is failed for a record, I want to
copy (append) that record (entire row) from the original data
worksheet to an exisiting xls file ?

I think I prbably can use ADO connection to get the record but Do you
think using an ADO connection would Not be better?
Or there is another way to do it?

Thanks a lot!

K.K.