Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 169
Default Not Copying All Rows



I am writing code which
loops through the files in a folder,
points at sheet 1 of each file,
copies all the non-empty cells in column B of each sheet 1 (and the rows),
pastes this to consolidate worksheet.
MY CODE IS FINE - ONLY PROBLEM IS THAT ITS NOT COPYING ALL ROWS

Sub SubGetMyData3()
Dim objFSO As Object
Dim objFolder As Object
Dim objFile As Object
Dim owb As Workbook
Dim i, j As Long

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("C:\My Documents\Career")
i = 1
j = 1
For Each objFile In objFolder.Files
If objFile.Type = "Microsoft Excel Worksheet" Then

Set owb = Workbooks.Open(Filename:=objFolder.Path & "\" &
objFile.Name)
owb.Worksheets("Sheet1").Cells(i, 2).EntireRow.Copy
Destination:=Worksheets("consolidate").Cells(j, 1)
i = owb.Worksheets("sheet1").Cells(Rows.Count, "A").Row + 1
j = Worksheets("consolidate").Cells(Rows.Count,
"A").End(xlUp).Row + 1
ActiveWorkbook.Close savechanges:=True
End If
Next
End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default Not Copying All Rows

Your code looks like it should only be copying the firstrow of those worksheets.

Sub SubGetMyData3()
Dim objFSO As Object
Dim objFolder As Object
Dim objFile As Object
Dim owb As Workbook
Dim j As Long
dim RngToCopy as range

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("C:\My Documents\Career")

j = 1
For Each objFile In objFolder.Files
If objFile.Type = "Microsoft Excel Worksheet" Then
Set owb = Workbooks.Open(Filename:=objFolder.Path _
& "\" & objFile.Name)
with owb.Worksheets("Sheet1")
set rngtocopy = .range("b1:B" _
& .cells(.rows.count,"B").end(xlup).row)
end with

rngtocopy.entireRow.Copy _
Destination:=Worksheets("consolidate").Cells(j, 1)

j = Worksheets("consolidate") _
.Cells(Rows.Count, "A").End(xlUp).Row + 1
owb.Close savechanges:=false 'why true????
End If
Next objFile
End Sub

teresa wrote:

I am writing code which
loops through the files in a folder,
points at sheet 1 of each file,
copies all the non-empty cells in column B of each sheet 1 (and the rows),
pastes this to consolidate worksheet.
MY CODE IS FINE - ONLY PROBLEM IS THAT ITS NOT COPYING ALL ROWS

Sub SubGetMyData3()
Dim objFSO As Object
Dim objFolder As Object
Dim objFile As Object
Dim owb As Workbook
Dim i, j As Long

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("C:\My Documents\Career")
i = 1
j = 1
For Each objFile In objFolder.Files
If objFile.Type = "Microsoft Excel Worksheet" Then

Set owb = Workbooks.Open(Filename:=objFolder.Path & "\" &
objFile.Name)
owb.Worksheets("Sheet1").Cells(i, 2).EntireRow.Copy
Destination:=Worksheets("consolidate").Cells(j, 1)
i = owb.Worksheets("sheet1").Cells(Rows.Count, "A").Row + 1
j = Worksheets("consolidate").Cells(Rows.Count,
"A").End(xlUp).Row + 1
ActiveWorkbook.Close savechanges:=True
End If
Next
End Sub


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Not Copying All Rows

You don't give many clues do you?

Perhaps?

Sub SubGetMyData3()
Dim objFSO As Object
Dim objFolder As Object
Dim objFile As Object
Dim owb As Workbook
Dim i As Long, j As Long

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("C:\My Documents\Career")
i = 1
j = 1
For Each objFile In objFolder.Files
If objFile.Type = "Microsoft Excel Worksheet" Then
Set owb = Workbooks.Open(Filename:=objFolder.Path & _
"\" & objFile.Name)
i = owb.Worksheets("sheet1").Cells(Rows.Count, "A").Row + 1
owb.Worksheets("Sheet1").Cells(1, 2).Resize(i, 1).EntireRow.Copy
_
Destination:=Worksheets("consolidate").Cells(j, 1)
j = Worksheets("consolidate").Cells(Rows.Count,
"A").End(xlUp).Row + 1
ActiveWorkbook.Close savechanges:=True
End If
Next
End Sub

--

HTH

RP
(remove nothere from the email address if mailing direct)


"teresa" wrote in message
...


I am writing code which
loops through the files in a folder,
points at sheet 1 of each file,
copies all the non-empty cells in column B of each sheet 1 (and the rows),
pastes this to consolidate worksheet.
MY CODE IS FINE - ONLY PROBLEM IS THAT ITS NOT COPYING ALL ROWS

Sub SubGetMyData3()
Dim objFSO As Object
Dim objFolder As Object
Dim objFile As Object
Dim owb As Workbook
Dim i, j As Long

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("C:\My Documents\Career")
i = 1
j = 1
For Each objFile In objFolder.Files
If objFile.Type = "Microsoft Excel Worksheet" Then

Set owb = Workbooks.Open(Filename:=objFolder.Path & "\" &
objFile.Name)
owb.Worksheets("Sheet1").Cells(i, 2).EntireRow.Copy
Destination:=Worksheets("consolidate").Cells(j, 1)
i = owb.Worksheets("sheet1").Cells(Rows.Count, "A").Row + 1
j = Worksheets("consolidate").Cells(Rows.Count,
"A").End(xlUp).Row + 1
ActiveWorkbook.Close savechanges:=True
End If
Next
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
Copying & Inserting Rows w/o Affecting other Rows Etc. LRay67 Excel Worksheet Functions 1 October 22nd 08 02:10 AM
Copying multiple rows to other worksheets (but amount of rows varies) - How? David Smithz Excel Discussion (Misc queries) 1 June 18th 06 04:31 PM
Copying Rows Dthmtlgod New Users to Excel 3 November 4th 05 05:50 AM
Copying over Rows Once teresa Excel Programming 2 December 13th 04 11:07 PM
Copying Rows when hiding other rows Neutron1871 Excel Worksheet Functions 2 November 3rd 04 11:38 PM


All times are GMT +1. The time now is 08:27 PM.

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"