Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1
Default Copy cells in Excel

I've been working on a code to copy cells from one excel file to
another excel file.
It seems to copy the cells but it's not indexing from the source file
through the next cells to copy.
It seems to never reach the last line of Next iSrow. It only goes to
Next iTrow until the end
over writing the cell it had previouly copied to the Target file. Any
help would be greatly
appreciated. I am only a beginner at this. Anyway here my code. What's
wrong with it?

Sub copydimensions()
Dim sSource As String, iWork As Long, sTarget As String
Dim iTrow As Long, iTcol As Long, iSrow As Long, iScol As Long
Dim iQuantity As Long, iWork2 As Long

'Workbooks.Open Filename:="C:\Users\2hot4u\Desktop\Painting
Estimate.xlsx"
sSource = "Dimensions.xlsm"
sTarget = "Painting Estimate.xlsx"
i = 0
iTrow = 0
iSrow = 0
iTcol = 0

For iSrow = 3 To 32000
If Trim$(Workbooks(sSource).Worksheets(1).Cells(iSrow , 1)) =
"" Then Exit For


iWork2 = Val(Workbooks(sSource).Worksheets(1).Cells(iSrow, 1))

For iTrow = 12 To 32000
If Trim$
(Workbooks(sTarget).Worksheets("Paintest").Cells(i Trow, 1)) = "" Then
Exit For


iWork =
Val(Workbooks(sTarget).Worksheets("Paintest").Cell s(iTrow, 1))

If iWork < iWork2 Then
Workbooks(sTarget).Worksheets("Paintest").Cells(iT row, 2)
= Workbooks(sSource).Worksheets(1).Cells(iSrow, 1)
Workbooks(sTarget).Worksheets("Paintest").Cells(iT row, 4)
= Workbooks(sSource).Worksheets(1).Cells(iSrow, 2)
Workbooks(sTarget).Worksheets("Paintest").Cells(iT row, 10)
= Workbooks(sSource).Worksheets(1).Cells(iSrow, 3)
Workbooks(sTarget).Worksheets("Paintest").Cells(iT row, 12)
= Workbooks(sSource).Worksheets(1).Cells(iSrow, 4)
End If

Next iTrow
Next iSrow

End Sub


  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1,522
Default Copy cells in Excel


NOT tested. Try and modify if necessary

Sub CombineFilesSAS()
Set ds = ActiveWorkbook
Workbooks.Open Filename:= _
"C:\Users\2hot4u\Desktop\Painting Estimate.xlsx"
ActiveWorkbook.Sheets(1).UsedRange.Copy _
ds.Sheets("paintest").Range("a65536").End(xlUp).Of fset(1)
ActiveWorkbook.Close
End Sub



On Nov 5, 9:48*pm, DeDan Austin wrote:
I've been working on a code to copy cells from one excel file to
another excel file.
It seems to copy the cells but it's not indexing from the source file
through the next cells to copy.
It seems to never reach the last line of Next iSrow. It only goes to
Next iTrow until the end
over writing the cell it had previouly copied to the Target file. Any
help would be greatly
appreciated. I am only a beginner at this. Anyway here my code. What's
wrong with it?

Sub copydimensions()
Dim sSource As String, iWork As Long, sTarget As String
Dim iTrow As Long, iTcol As Long, iSrow As Long, iScol As Long
Dim iQuantity As Long, iWork2 As Long

'Workbooks.Open Filename:="C:\Users\2hot4u\Desktop\Painting Estimate.xlsx"
sSource = "Dimensions.xlsm"
sTarget = "Painting Estimate.xlsx"
i = 0
iTrow = 0
iSrow = 0
iTcol = 0

* * For iSrow = 3 To 32000
* * * * If Trim$(Workbooks(sSource).Worksheets(1).Cells(iSrow , 1)) =
"" Then Exit For

* * * * iWork2 = Val(Workbooks(sSource).Worksheets(1).Cells(iSrow, 1))

* * For iTrow = 12 To 32000
* * * * If Trim$
(Workbooks(sTarget).Worksheets("Paintest").Cells(i Trow, 1)) = "" Then
Exit For

* * * * * * iWork =
Val(Workbooks(sTarget).Worksheets("Paintest").Cell s(iTrow, 1))

* * * * If iWork < iWork2 Then
* * * * * * Workbooks(sTarget).Worksheets("Paintest").Cells(iT row, 2)
= Workbooks(sSource).Worksheets(1).Cells(iSrow, 1)
* * * * * * Workbooks(sTarget).Worksheets("Paintest").Cells(iT row, 4)
= Workbooks(sSource).Worksheets(1).Cells(iSrow, 2)
* * * * * * Workbooks(sTarget).Worksheets("Paintest").Cells(iT row, 10)
= Workbooks(sSource).Worksheets(1).Cells(iSrow, 3)
* * * * * * Workbooks(sTarget).Worksheets("Paintest").Cells(iT row, 12)
= Workbooks(sSource).Worksheets(1).Cells(iSrow, 4)
* * * * End If

* * Next iTrow
* * * * Next iSrow

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
does any one know to copy cells within an IF statement in Excel DonE Excel Worksheet Functions 10 June 2nd 09 12:42 AM
Copy and paste versus copy and insert copied cells Alana New Users to Excel 1 September 28th 07 08:58 PM
Excel: cells prepare to copy how I remove it User VB Excel Excel Discussion (Misc queries) 3 August 23rd 07 04:30 PM
Copy/Paste how to avoid the copy of formula cells w/o calc values Dennis Excel Discussion (Misc queries) 10 March 2nd 06 10:47 PM
copy & paste spreadsheet cells from excel to outlook to excel mismarple Excel Discussion (Misc queries) 1 September 20th 05 11:16 PM


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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"