Is This Possible?

Dazzawm

Well-known Member
Joined
Jan 24, 2011
Messages
3,786
Office Version
  1. 365
Platform
  1. Windows
I have a folder with 30 files in. Is it possible to use a code to open all files look for a word that will be in column H and then put another word in column K in one fail swoop, rather than opening each file individually? Thanks.
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
first of all... it's "one FELL swoop".
second, what word are you looking for, and what do you want to do with it?
 
Upvote 0
Thanks for picking me up on my spelling, the word it needs to look for in column H is 'Cube' and the word it needs to put in column K in each file is 'Van'.
 
Upvote 0
try this
Code:
Private Sub AllFolderFiles()
    Dim wb As Workbook
    Dim TheFile As String
    Dim MyPath As String
    MyPath = GetFolder
    ChDrive Left(MyPath, Application.WorksheetFunction.Search(":", MyPath))
    ChDir MyPath
    TheFile = Dir("*.xls")
    On Error Resume Next
    Do While TheFile <> ""
        Application.ScreenUpdating = False
        Set wb = Workbooks.Open(MyPath & "\" & TheFile)
        wb.Activate
        For i = 1 To Cells(Rows.Count, "h").End(xlUp).Row
            If Cells(i, "H") = "Cube" Then
                Cells(i, "k") = "Van"
            End If
        Next i
        wb.Close
        Application.ScreenUpdating = True
        TheFile = Dir
    Loop
    Set wb = Nothing
End Sub
Function GetFolder(Optional strPath As String) As String
    Dim fldr As FileDialog
    Dim sItem As String
    Set fldr = Application.FileDialog(msoFileDialogFolderPicker)
    With fldr
        .Title = "Select a Folder"
        .AllowMultiSelect = False
        .InitialFileName = strPath
        If .Show <> -1 Then GoTo NextCode
        sItem = .SelectedItems(1)
    End With
NextCode:
    GetFolder = sItem
    Set fldr = Nothing
End Function
 
Upvote 0
Do I need to put this in just one file within the folder they are kept? Also can you highlight the parts I need to edit. Thanks.
 
Upvote 0
no need to edit anything. just make sure all the worksheets (.xls) are in the same folder.

well.... change .xls to .xlsm or whatever you need to. but, that should be it.
 
Upvote 0
Where do I put the code? I cant seem to find it anywhere!
 
Upvote 0
put it in a "module". It's a "container" for code.

press alt+f11 to get to the vb editor.
go to the left where you see "sheet1", "thisworkbook", etc. and right click add module
paste the code I put there

close out of that (save it of course)

click on view>macros>(whatever you called the code)
 
Upvote 0
Still cant see it. It wouldnt be because its a private sub ?
 
Upvote 0

Forum statistics

Threads
1,224,583
Messages
6,179,682
Members
452,937
Latest member
Bhg1984

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