Macro needed to extract a text in particular cell in a workbook

vignesh_thegame

New Member
Joined
Sep 30, 2013
Messages
48
Hi,
i have around 1000 workbook with same formats in a folder, i need a macro that opens all the workbook and copy ROW 5 text alone and paste this in another excel one by one...

i have given a example below of how my excel is.... i need to extract the "Upper Saddle River, NJ" text which was on column A,B,C in row 5 to another excel. This macro must open all my 1000 workbooks and extract the text and place in a single excel one by one.. Can any one help me on this.???:eek:
ABCDEFGHIJKLMNOPQRS
1Attn:
2Savoula AmanatidisInvoice Date:12-17-2013
3Prentice Hall - ECPLW ME Job #:9482
41 Lake StreetP.O. #:0411662826-1
5Upper Saddle River, NJ07458Invoice #:26103 F
6Final invoice on your title, Troyka
7Quick Access Compact

<tbody>
</tbody>
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
.
.

Please try the following macro. You don't need to have any of your workbooks already open in order to run the macro; simply run it from a new workbook.

Before running, you'll first need to change the line SFold = "C:\Users\jsmith\Desktop" to match the path where your workbooks are located.

Please also note that, if you're looping through 1,000+ workbooks, the macro will likely take some time to run. Therefore, I've placed an alert at the end that will tell you when it has finished running.


Code:
Sub Copy_A5_Value()

    'For source books:
    Dim SFold As String
    Dim SFile As String
    Dim SPath As String
    Dim SBook As Workbook
    Dim SNumb As Long
    
    'For destination book:
    Dim DBook As Workbook
    
    'Set folder containing source books
    'Change as necessary...
    SFold = "C:\Users\jsmith\Desktop"
    
    SFile = Dir(SFold & Application.PathSeparator & "*.xl*")
    
    'Exit if no source books found
    If SFile = vbNullString Then
        MsgBox _
            Prompt:="No files found.", _
            Buttons:=vbCritical
        Exit Sub
    End If
    
    With Application
        .ScreenUpdating = False
        .DisplayAlerts = False
    End With
    
    'Create destination book
    Set DBook = Workbooks.Add
    
    'Loop through source
    'books and copy
    'values from cell A5...
    
    SNumb = 0
    Do While SFile <> vbNullString
        SNumb = SNumb + 1
        SPath = SFold & Application.PathSeparator & SFile
        Set SBook = Workbooks.Open(Filename:=SPath)
        SBook.Worksheets(1).Range("A5").Copy
        DBook.Worksheets(1).Range("A" & SNumb).PasteSpecial Paste:=xlPasteValues
        SBook.Close SaveChanges:=False
        SFile = Dir
    Loop
    
    With Application
        .ScreenUpdating = True
        .DisplayAlerts = True
    End With
    
    'Notification that
    'macro is finished...
    
    MsgBox _
        Prompt:="Finished.", _
        Buttons:=vbInformation

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,985
Messages
6,122,603
Members
449,089
Latest member
Motoracer88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top