Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default trying to use xlToRight but having problems

What I am trying to do is use VB Code to take data from 4 files within
a folder and copy the data
to a master file in another workbook.
Each file in the folder contains data in columns A&B, and has a dynamic
amount of rows depending on the file.

The following code is what I have so far, which works(kind of)!!!
Sub Consolidate()
With Application
.DisplayAlerts = False
.EnableEvents = False
.ScreenUpdating = False
End With


With Application.FileSearch
.NewSearch
'Change this to your directory
.LookIn = "C:\Documents and Settings\banderson\Desktop\freight
thing"
.SearchSubFolders = False
.FileType = msoFileTypeExcelWorkbooks
If .Execute() 0 Then
Set Basebook = Workbooks.Open(.FoundFiles(1))
For i = 2 To .FoundFiles.Count
Set myBook = Workbooks.Open(.FoundFiles(i))
Range("A1").CurrentRegion.Copy _
Basebook.Worksheets(1).Range("A1").End(xlColumn).O ffset(0, 2)
myBook.Close
Next i
Basebook.SaveAs Application.GetSaveAsFilename("FREIGHT_MASTER")
End If
End With


With Application
.DisplayAlerts = True
.EnableEvents = True
.ScreenUpdating = True
End With

End Sub

This code gives me the first and last record within my folder, but if i
change
Range("A1").CurrentRegion.Copy _
Basebook.Worksheets(1).Range("A1").End(xlColumn).O ffset(0, 2)
to be xlToRight it gives me an error:
Run-time Error '1004'
Application-Defined or object-defined error

If I use the same line of code and put in xlDown it works, grabs all
data from 4 worksheets and
copies them to master file but all in the first column down.

I want it to copy all the data across and not down.

If anyone could shed some light on how to go about this to finish off
my code to make this work
it would be greatly appreciated.
Thanks

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default trying to use xlToRight but having problems

Alok,
You are the man
Worked like a charm!!!
Thank you for seeing what I couldn't!!!

Alok wrote:
Try the following- assumes that all files have data in only 2 columns

Range("A1").CurrentRegion.Copy _
Basebook.Worksheets(1).Cells(1,(i-1)*2+1)

Alok

" wrote:

What I am trying to do is use VB Code to take data from 4 files within
a folder and copy the data
to a master file in another workbook.
Each file in the folder contains data in columns A&B, and has a dynamic
amount of rows depending on the file.

The following code is what I have so far, which works(kind of)!!!
Sub Consolidate()
With Application
.DisplayAlerts = False
.EnableEvents = False
.ScreenUpdating = False
End With


With Application.FileSearch
.NewSearch
'Change this to your directory
.LookIn = "C:\Documents and Settings\banderson\Desktop\freight
thing"
.SearchSubFolders = False
.FileType = msoFileTypeExcelWorkbooks
If .Execute() 0 Then
Set Basebook = Workbooks.Open(.FoundFiles(1))
For i = 2 To .FoundFiles.Count
Set myBook = Workbooks.Open(.FoundFiles(i))
Range("A1").CurrentRegion.Copy _
Basebook.Worksheets(1).Range("A1").End(xlColumn).O ffset(0, 2)
myBook.Close
Next i
Basebook.SaveAs Application.GetSaveAsFilename("FREIGHT_MASTER")
End If
End With


With Application
.DisplayAlerts = True
.EnableEvents = True
.ScreenUpdating = True
End With

End Sub

This code gives me the first and last record within my folder, but if i
change
Range("A1").CurrentRegion.Copy _
Basebook.Worksheets(1).Range("A1").End(xlColumn).O ffset(0, 2)
to be xlToRight it gives me an error:
Run-time Error '1004'
Application-Defined or object-defined error

If I use the same line of code and put in xlDown it works, grabs all
data from 4 worksheets and
copies them to master file but all in the first column down.

I want it to copy all the data across and not down.

If anyone could shed some light on how to go about this to finish off
my code to make this work
it would be greatly appreciated.
Thanks



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
Problems with ngs T. Valko Excel Worksheet Functions 2 January 6th 10 12:05 AM
aauugghhh...#div/o problems & various average formula problems acbel40 Excel Worksheet Functions 5 October 19th 09 05:00 PM
Problems merging an excel file due to code or file problems? Cindy M -WordMVP- Excel Programming 0 September 14th 04 02:58 PM
(xlToRight) dallas Excel Programming 1 September 3rd 04 08:40 PM
Question about ).End(xlToRight) Bob Benjamin Excel Programming 5 November 10th 03 05:04 AM


All times are GMT +1. The time now is 09:49 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"