Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 106
Default Searching for and Pasting Data to a new file

I have about 148 files in an Excel directory. Is there an easy way to search
the first four rows of all these files and find the word 'title'. If that
word exists, I would then like to copy the word that is next (the cell to the
right) to that word and paste it in a new file. If the word 'title' is in
cell K4, the actual title will be in L4.

I would then like to copy the contents of the title and the name of the file
(or its path) to a new file called, say, Lists.xls.

Not all files in the directory will contain the word title. All the files
currently reside in C:\UFBooks

If this can be done it would be a huge time saver. Thanks for you help.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Searching for and Pasting Data to a new file

Elaine,

Try the macro below. Let me know if it works out OK.

This assumes that "Title" is only found once in the top four rows....

HTH,
Bernie
MS Excel MVP

Option Explicit
Sub FindTitles()
Dim mySht As Worksheet
Dim WorkFile As String
Dim myPath As String
Dim myFind As Range

Set mySht = ActiveSheet
With Application
.DisplayAlerts = False
.ScreenUpdating = False
End With

myPath = "C:\UFBooks\"
WorkFile = Dir(myPath & "*.xls")
Do While WorkFile < ""
Workbooks.Open Filename:=myPath & WorkFile
Set myFind = Range("1:4").Find("Title")
If myFind Is Nothing Then GoTo NotFound
mySht.Cells(Rows.Count, 1).End(xlUp)(2).Value = _
WorkFile
mySht.Cells(Rows.Count, 2).End(xlUp)(2).Value = _
myFind(1, 2).Value
NotFound:
ActiveWorkbook.Close False
WorkFile = Dir()
Loop

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

End Sub


"Elaine" wrote in message
...
I have about 148 files in an Excel directory. Is there an easy way to search
the first four rows of all these files and find the word 'title'. If that
word exists, I would then like to copy the word that is next (the cell to the
right) to that word and paste it in a new file. If the word 'title' is in
cell K4, the actual title will be in L4.

I would then like to copy the contents of the title and the name of the file
(or its path) to a new file called, say, Lists.xls.

Not all files in the directory will contain the word title. All the files
currently reside in C:\UFBooks

If this can be done it would be a huge time saver. Thanks for you help.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 106
Default Searching for and Pasting Data to a new file

Thank you very much for your help, Bernie.

I ran the macro but nothing seemed to happen!

I opened a blank workbook with sheet1 and ran the macro and nothing happened.
I also opened a file called list.xls and ran the file and nothing happened.
I also ran Debug | Compile Project and found no errors. (The only changes
that I made were to remove the underscores after the "=" signs.

I double checked and found that there were several files with the word title
and a title next to it.

Is there any other thing that you can suggest. I am sure that I have made
some mistake but I don't know what it is.

--Elaine

"Bernie Deitrick" wrote:

Elaine,

Try the macro below. Let me know if it works out OK.

This assumes that "Title" is only found once in the top four rows....

HTH,
Bernie
MS Excel MVP

Option Explicit
Sub FindTitles()
Dim mySht As Worksheet
Dim WorkFile As String
Dim myPath As String
Dim myFind As Range

Set mySht = ActiveSheet
With Application
.DisplayAlerts = False
.ScreenUpdating = False
End With

myPath = "C:\UFBooks\"
WorkFile = Dir(myPath & "*.xls")
Do While WorkFile < ""
Workbooks.Open Filename:=myPath & WorkFile
Set myFind = Range("1:4").Find("Title")
If myFind Is Nothing Then GoTo NotFound
mySht.Cells(Rows.Count, 1).End(xlUp)(2).Value = _
WorkFile
mySht.Cells(Rows.Count, 2).End(xlUp)(2).Value = _
myFind(1, 2).Value
NotFound:
ActiveWorkbook.Close False
WorkFile = Dir()
Loop

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

End Sub


"Elaine" wrote in message
...
I have about 148 files in an Excel directory. Is there an easy way to search
the first four rows of all these files and find the word 'title'. If that
word exists, I would then like to copy the word that is next (the cell to the
right) to that word and paste it in a new file. If the word 'title' is in
cell K4, the actual title will be in L4.

I would then like to copy the contents of the title and the name of the file
(or its path) to a new file called, say, Lists.xls.

Not all files in the directory will contain the word title. All the files
currently reside in C:\UFBooks

If this can be done it would be a huge time saver. Thanks for you help.




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
searching a text file and importing selected data brian Excel Discussion (Misc queries) 0 October 30th 07 08:44 PM
reading from another file and pasting to current file, "combobox" Darius New Users to Excel 1 September 26th 05 07:13 AM
Pasting on Filtered Data Sheets without pasting onto hidden cells CCSMCA Excel Discussion (Misc queries) 1 August 28th 05 01:22 PM
File Searching Lawson Excel Programming 1 January 30th 04 03:13 AM
Copying rows from one file and pasting into a new file Tina Excel Programming 0 August 25th 03 04:34 AM


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