Page 2 of 4 FirstFirst 1234 LastLast
Results 11 to 20 of 40

Thread: Notes tests. Excel VBA Folder File Search

  1. #11
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,439
    Rep Power
    10
    In support of these Forum Threads

    https://www.excelforum.com/developme...ml#post4440512
    https://excel.tips.net/T008233_Findi...e_Desktop.html
    http://www.excelfox.com/forum/showth...ll=1#post10420
    http://www.excelfox.com/forum/showth...ll=1#post10421




    Original Post was the eigth Post after this one_.....
    http://www.eileenslounge.com/viewtop...185272#p175068
    _...... but it is no longer there currently

    _.. Original Post: ( Post Split over several Posts in this Thread ( It was one Post originally )
    -::::::................
    )

    Hi,
    I found the code here to loop through all folders and sub Folders very interesting and revealing.
    I am only a novice but have answered more Threads then I can remember doing this and almost always the method I and others use is the same one. The code here is different..

    So I am mainly just adding another solution as well as discussing and comparing with the solution given here by Rudi.

    I am mainly looking at applying the codes to get to the point of being able to "do stuff" with each File. For the OP "doing stuff" was to Find and Replace Values in all excel files of a main Folder, including all Files in Sub Folders. But the actual Doing stuff is rarely the difficult bit. The main work is to "get at " all Files.

    What really caught my eye with this Thread is that it does this without using the, as many people find a big mystery, the process of recursion.

    I thought it would be very useful to write a code where the "doing stuff " was to print out to a Spreadsheet a Full Listing of all The Folders, Sub Folders., and all files within.

    So for any required " doing stuff " code you could first run the code, which asks you to select your main Folder. The Print out lets you see and check that you are "getting" at each File you want. The code can then be modified by simply replacing at those lines which print out the information, the code lines necessary to do stuff to each file and / or Folder.

    _..........................................
    I will present two codes, a version of Rudi's and mine which is based on the classical Recursion Way.


    Here then some quick notes on the codes.
    Rem 1) Just some Worksheet info. Currently the Code accesses the first tab from the left ( Usually your "Sheet1" ). Identical for both codes.
    Rem 2) Identical for Both Codes. Calls up a dialogue box in which you may enter the Start Folder in which all Folders and Sub Folders of interest are in. ( There are at least 3 ways in VBA I know to get that, I just chose one of them:
    http://www.mrexcel.com/forum/general...plication.html
    ( The one using an Object that has a lot to do with Window things ).
    http://www.mrexcel.com/forum/general...plication.html
    I did the above just to practice something new to me.
    The Application.FileDialog(msoFileDialogFolderPicker)
    Originally dine by Rudis Way is probably better. That is just a VBA Property that pulls up a dialogue box, in this case the one that lets you pick a Folder.
    _................................................. ............
    Rem 3) Similar for both codes.
    Sets up and allows us to use the Microsoft Scripting Runtime Library, which allows us to do lots with Files and related things.

    Rem 4) Positional Info variable declaration.
    Variables for Positons of where I print the Folder and File Info in the Worksheet.
    For that the Range Object of the Top Left of where a "Explorer" Listing should go has the Cells Property applied using the Co ordinates I determine to give the Position in the Worksheet in which to paste out the Folder or File name
    For Rudis Code the Queue thing is also declared
    For Rudis Code I have variables for the count of Folders in the next Folder level, and for the count of the current Folder level being looped through This is the actual stand at the time within the Queue.

    Rem 5 ) Here the codes differ.
    Explanations are given extensively in the code 'Comments, best viewed in the VB Code Window whilst stepping through the code in debug ( F8 ) ( Whilst if possible also looking at the Spreadsheet at the same time )
    Briefely in Words.

    My code. The Classic recursion Type.

    The Routine at Rem 5A) is called initially from the
    Sub DoStuffInFoldersInFolderRecursion()
    Code. It passes to it this first time the Main Folder.
    This called subroutine starts going into the next level "down" or "to the right" of Sub Folders in the given Original Main Folder.
    It does stuff for Each Sub Folder and files, if any , therein. ( Using a For Next Loop typically )
    After that it calls itself !!!! It takes into it the current Sub Folder.
    At this point most people get confused. I think, as I am thick, and can understand the following explanation , then it may be easy for most people to understand

    The thing that is often missing at this point is knowing what VBA actually does when this happens. Quite simply it makes a NEW Copy of the Routine, completely independent of the Original Routine calling it. And it starts running that. The original Routine is "frozen" by VBA. And VBA stores somewhere( typically referred to as in a "Stack Row" or "Stack" ) all the variable values used in the Calling Routine and "freezes" them at their current values as well.

    In the New copy all variable are new and independent of those in the Original. Unfortunately you never think you see this new Copy, but you do. If you step through such a recursion code, when it "looks" like it springs back to the original when the Code calls itself, you are actually seeing at that point the Copy.

    So you see, if you have a couple of Folders, and the first has a Sub Folder in it then the following happens:
    You do stuff in the First Folder. Then that Routine "freezes" as it calls itself. The current Sub Folder is taken into the "Copy" Routine. The "Copy" Routine then Does the same for the all Sub Folders now in the current Sub Folder. Important is that the Code line which calls itself is within the main For Next. So if there are no more Sub Folders, the Copy Routine will end. This occurs in our example here after the one Sub Folder. Effectively the "Copy" Routine then "dies" The original Routine then Unfreezes. So the next of our two Folders is gone through.

    The only difficulty I had in writing the particular Recursion code is that I wanted to show each Folder "level" down the Folder Chain at each column going "down" or "to the right" as typically seen in a classic Explorer Window. The problem is how do I know which "Copy" Routine I am in. Every successive Copy will relate to a run in a the next "down" or "to the right. I cannot simply add a progressively increasing count, as in the recursion Code I will be going "back and forth" depending on if and how many Sub folders there are. I need a way to know at which "level" of Sub Folders I am in when in any progression back and forth.
    I do that as follows. I mention it here as it does demonstrate clearly again how recursion works.
    Inside the Routine towards the start is a variable,
    CopyNumber.
    This will be a unique variable for each "Copy" Routine. Every time the Routine is called a number is taken in at the value inside a variable in the signature line
    CopyNumberFroNxtLvl
    For the very first call it is set to 1 in a variable whose value is taken in at its value, as a value, in the Signature line
    Within the Routine this value is given to
    CopyNumber.
    Only
    If CopyNumber = 0
    That is to say if
    CopyNumber
    Had never been given a number
    When the function calls itself to takes in by value at the value iif using the value of
    CopyNumber + 1
    ( Call LoopThroughEachFolderAndItsFile(myFldrs, celTL, rCnt, CopyNumber + 1) )

    This has the effect that when you go to the "next down" or "next level to the right" only the first time will
    CopyNumber
    Be assigned, and its value will take an incremented number giving an indication of you "level"

    This value is frozen when you go "further down" in the next "Copy Routine" . But When you come back up, it "thaws out" and is used within so that my line which prints out information will be in the correct "column" which is an indication in my final Output of the "level" of my folder ( and possibly Files within )

    (celTL.Cells(rCnt, 1).Value = myFldrs.Path: celTL.Cells(rCnt, CopyNumber).Offset(0, 2).Value = myFldrs.Name )

    ( celTL.Cells(rCnt, CopyNumber).Offset(0, 2).Value = oFile.Name )
    Last edited by DocAElstein; 01-23-2020 at 04:08 PM.
    ….If you are my competitor, I will try all I can to beat you. But if I do, I will not belittle you. I will Salute you, because without you, I am nothing.
    If you are my enemy, we will try to kick the fucking shit out of you…..
    Winston Churchill, 1939
    Save your Forum..._
    _...KILL A MODERATOR!!

  2. #12
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,439
    Rep Power
    10
    _................................................. .........

    Rudi's code from Rem 5R)

    This works differently in a way I have never seen before. There is no need to call a "recursion Routine"

    Initially The main Folder is "put" into a "Queue" ( at the " back " of it )
    https://msdn.microsoft.com/en-us/lib...(v=vs.60).aspx
    https://msdn.microsoft.com/de-de/lib...(v=vs.90).aspx
    ( I expect in the "Queue" is just holding the Pointer to the actual Folder Object
    The code the does a similar For Next as in my Code. One major difference is that the first thing it does is at each Folder is to go through every Sub Folder therein and "Put" it at the "back" of the queue. It takes the current folder being "looked" at "out" of the Queue from the "front".

    It effectively then "stacks up all" the Folders in the next level down. Eventually after it goes through every Folder in the current level it will reach the point where it starts on the next level. So effectively it does not go "back and forth" like mine does. Rather it has "looking up" or "back from the front" first all the first level Folders, then all the next level Folders , then all the next, and so on.
    If you look at the difference in the output that I get from mine and Rudi's code, you will soon see the corresponding difference.

    Again the tricky bit for me was to get a Variable to indicate the "level" or "column to the left".

    What I do in this case is count every time a Sub Folder is put in the back of the Queue.
    NxtLvlCnt
    This will finally give an indication of the Number of Sub folders at the next level.
    I have second count variable
    CurrentLvlCnt
    Which is originally set to the last level count ( set initially to one for the original main folder ), which is successively decreased each time a Folder is "taken out" of the queue. When it reaches zero it is an indication that we have reached the next series of Next level Sub Folders. When that occurs it is given the value of the next level Count, and the next level Cont is then reset to Zero.

    _................................................. .......

    For both code I finally added a bit of Error handling. I did this as when I tested with many real files , I often had an error if , for example the "doing stuff" involved opening a file. If this happens you are told what error occurred and to which file, then you go on to the next. ( I assume that errors do not occur in the original code that just Prints out the "explorer type" Listing. If it did I expect the output could go a bit out if step !! ) )

    _...............................................

    So I give here some typical output from a run of both codes. To make it a bit easier I include the example set of Folders I used. ( I hope they all come up. By me only a few Folders come up, although the are "indicted as all there " ? ? )
    https://app.box.com/s/onj6ntvwkxbo1088x7e0tca2gst45hnq
    ( Edit : Here is another Folder to try https://app.box.com/s/9e6xnb65fijjhl7bk0q6gzzriihkzibw )


    words I have a main
    EileensFldr

    That has three sub folders in it. Therein are files and further sub Folders and files etc…. as seen in the listing the Code gives.

    Initially the code is set to run from a file in the same directory as folder EileensFldr
    Last edited by DocAElstein; 01-23-2020 at 02:44 PM.
    ….If you are my competitor, I will try all I can to beat you. But if I do, I will not belittle you. I will Salute you, because without you, I am nothing.
    If you are my enemy, we will try to kick the fucking shit out of you…..
    Winston Churchill, 1939
    Save your Forum..._
    _...KILL A MODERATOR!!

  3. #13
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,439
    Rep Power
    10
    Output Given from my code

    Using Excel 2007 32 bit
    Row\Col
    A
    B
    C
    D
    E
    F
    1
    H:\Excel0202015Jan2016\ExcelForum\wbSheetMaker\Eil eensFldr EileensFldr
    2
    3
    H:\Excel0202015Jan2016\ExcelForum\wbSheetMaker\Eil eensFldr\Fldr1_1 Fldr1_1
    4
    File1_1a.xlsx
    5
    File1_1b.xlsx
    6
    7
    H:\Excel0202015Jan2016\ExcelForum\wbSheetMaker\Eil eensFldr\Fldr1_2 Fldr1_2
    8
    File1_2a.xlsx
    9
    File1_2b.xlsx
    10
    File1_2c.xlsx
    11
    12
    H:\Excel0202015Jan2016\ExcelForum\wbSheetMaker\Eil eensFldr\Fldr1_2\Fldr1_2_1 Fldr1_2_1
    13
    File1_2_1a.xlsx
    14
    File1_2_1b.xlsx
    15
    16
    H:\Excel0202015Jan2016\ExcelForum\wbSheetMaker\Eil eensFldr\Fldr1_2\Fldr1_2_1\Fldr1_2_1_1 Fldr1_2_1_1
    17
    File1_2_1_1a.xlsx
    18
    19
    H:\Excel0202015Jan2016\ExcelForum\wbSheetMaker\Eil eensFldr\Fldr1_2\Fldr1_2_1\Fldr1_2_1_2 Fldr1_2_1_2
    20
    File1_2_1_2a.xlsx
    21
    File1_2_1_2b.xlsx
    22
    23
    H:\Excel0202015Jan2016\ExcelForum\wbSheetMaker\Eil eensFldr\Fldr1_3 Fldr1_3
    24
    25
    H:\Excel0202015Jan2016\ExcelForum\wbSheetMaker\Eil eensFldr\Fldr1_3\Fldr1_3_1 Fldr1_3_1
    26
    27
    H:\Excel0202015Jan2016\ExcelForum\wbSheetMaker\Eil eensFldr\Fldr1_3\Fldr1_3_1\Flsr1_3_1_1 Flsr1_3_1_1
    28
    29
    H:\Excel0202015Jan2016\ExcelForum\wbSheetMaker\Eil eensFldr\Fldr1_3\Fldr1_3_1\Flsr1_3_1_1\Fldr1_3_1_1 _1 Fldr1_3_1_1_1
    EFFldr
    Last edited by DocAElstein; 01-23-2020 at 02:45 PM.
    ….If you are my competitor, I will try all I can to beat you. But if I do, I will not belittle you. I will Salute you, because without you, I am nothing.
    If you are my enemy, we will try to kick the fucking shit out of you…..
    Winston Churchill, 1939
    Save your Forum..._
    _...KILL A MODERATOR!!

  4. #14
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,439
    Rep Power
    10
    Correspondoing Output given by Rudi's code

    Using Excel 2007 32 bit
    Row\Col
    A
    B
    C
    D
    E
    F
    1
    H:\Excel0202015Jan2016\ExcelForum\wbSheetMaker\Eil eensFldr EileensFldr
    2
    3
    H:\Excel0202015Jan2016\ExcelForum\wbSheetMaker\Eil eensFldr\Fldr1_1 Fldr1_1
    4
    File1_1a.xlsx
    5
    File1_1b.xlsx
    6
    7
    H:\Excel0202015Jan2016\ExcelForum\wbSheetMaker\Eil eensFldr\Fldr1_2 Fldr1_2
    8
    File1_2a.xlsx
    9
    File1_2b.xlsx
    10
    File1_2c.xlsx
    11
    12
    H:\Excel0202015Jan2016\ExcelForum\wbSheetMaker\Eil eensFldr\Fldr1_3 Fldr1_3
    13
    14
    H:\Excel0202015Jan2016\ExcelForum\wbSheetMaker\Eil eensFldr\Fldr1_2\Fldr1_2_1 Fldr1_2_1
    15
    File1_2_1a.xlsx
    16
    File1_2_1b.xlsx
    17
    18
    H:\Excel0202015Jan2016\ExcelForum\wbSheetMaker\Eil eensFldr\Fldr1_3\Fldr1_3_1 Fldr1_3_1
    19
    20
    H:\Excel0202015Jan2016\ExcelForum\wbSheetMaker\Eil eensFldr\Fldr1_2\Fldr1_2_1\Fldr1_2_1_1 Fldr1_2_1_1
    21
    File1_2_1_1a.xlsx
    22
    23
    H:\Excel0202015Jan2016\ExcelForum\wbSheetMaker\Eil eensFldr\Fldr1_2\Fldr1_2_1\Fldr1_2_1_2 Fldr1_2_1_2
    24
    File1_2_1_2a.xlsx
    25
    File1_2_1_2b.xlsx
    26
    27
    H:\Excel0202015Jan2016\ExcelForum\wbSheetMaker\Eil eensFldr\Fldr1_3\Fldr1_3_1\Flsr1_3_1_1 Flsr1_3_1_1
    28
    29
    H:\Excel0202015Jan2016\ExcelForum\wbSheetMaker\Eil eensFldr\Fldr1_3\Fldr1_3_1\Flsr1_3_1_1\Fldr1_3_1_1 _1 Fldr1_3_1_1_1
    EFFldr
    Last edited by DocAElstein; 01-23-2020 at 02:58 PM.
    ….If you are my competitor, I will try all I can to beat you. But if I do, I will not belittle you. I will Salute you, because without you, I am nothing.
    If you are my enemy, we will try to kick the fucking shit out of you…..
    Winston Churchill, 1939
    Save your Forum..._
    _...KILL A MODERATOR!!

  5. #15
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,439
    Rep Power
    10
    Codes:
    Rudi's Code
    Sub ReplaceInAllSubFoldersRudisQing()

    '' http://www.excelforum.com/excel-prog...ubfolders.html



    Code:
    '  Rudi     http://www.eileenslounge.com/viewtopic.php?f=27&t=22499
    Sub ReplaceInAllSubFoldersQing()
    Rem 1Q) Some Worksheets and General Variables Info
    Dim ws As Worksheet: Set ws = ThisWorkbook.Worksheets.Item(1) 'Worksheets("RudyMSRQueue") 'CHANGE TO SUIT YOUR WORKSHEET
    Dim strDefpath As String: Let strDefpath = ThisWorkbook.Path ' Any Path to Folder to test this code! here we simply use the Path where the File with this code in is
    Dim strDefFldr As String: Let strDefFldr = "EileensFldr" 'Just for an initial suggestion
    Rem 2Q) Get Folder Info ( Using VBA Application.FileDialog(msoFileDialogFolderPicker) Property )
    Dim strWB As String
      With Application.FileDialog(msoFileDialogFolderPicker)
        .Title = "Folder Select "
        .AllowMultiSelect = False
            If .Show <> -1 Then
            Exit Sub
            End If
        Let strWB = .SelectedItems(1) & "\"
      End With
    
    Rem 3Q) Microsoft Scripting Runtime Library
    'Dim FSO As Object: Set FSO = CreateObject("Scripting.FileSystemObject")'Late Binding
    Dim FSO As Scripting.FileSystemObject 'Early Binding alternative  activate a reference to the Microsoft Scripting Runtime Library in the Tools > References menu of VBE.
    Set FSO = New Scripting.FileSystemObject
    
    Rem 4Q)'Some variables for Positon of Things
    Dim rCnt As Long, clmLvl As Long: Let clmLvl = 1: Let rCnt = -1 'rowCount is genaraly increase for a new entry, Column "level" is intended to give an indication of how far down ( to he right ) you are in the Folder chain. Ste to 1 for the first mainn Initial Folder.
    Dim CurrentLvlCnt As Long: CurrentLvlCnt = 1 'Count of the Number of Folders in the Folder level currently beig run through.
    Dim NxtLvlCnt As Long 'Count of the Number of Folders in the next level
    Dim queue As Collection
    Set queue = New Collection
    queue.Add FSO.GetFolder(strWB) 'Main Folder Put at position 1 of Queue'''''
    Dim celTL As Range: Set celTL = ws.Range("A1") 'Top left of where Listing should go
    'Application.ScreenUpdating = False
    
    Rem 5Q) Main loop. Do While Queue is not Empty effectivelly goes through all Folders
    Dim oFile As Variant, oFolder As Variant, oSubfolder As Variant '                                                                 Can also be variant Types or Objects. - Must be for Late Binding
        Do While queue.Count > 0 'Main Loop. Does as many times as there are things ( Folders here ) stacked in the Queue========
        Set oFolder = queue(1) 'Next Folder .... effectively
        queue.Remove 1 'de-queue'......"taken" from start of Queue. ( Actually it is assigned to a variable, then removed from the Queue, which probably just has the Pointer to it.
        CurrentLvlCnt = CurrentLvlCnt - 1 'de-the count for numbers in in this current Folder level
        ''''''''Doing Stuff For the Folder
        rCnt = rCnt + 2 'Move on a line and a spare Line for every Folder Entry
        celTL.Cells(rCnt, 1).Value = oFolder.Path: celTL.Cells(rCnt, clmLvl).Offset(0, 1).Value = oFolder.Name 'Cell poroperty of Top Left Cell Range Object uset to position output.
        ''''''''End Doing Stuff for each Folder
        '5Qa) Add any Sub Folders from current Folder at end of queue
            For Each oSubfolder In oFolder.SubFolders 'For as many ( if any ) Sub Folders In the Current Folder
            queue.Add oSubfolder 'en-queue.. add the Sub Folder on at the end of the Queue
            NxtLvlCnt = NxtLvlCnt + 1 'en-the count of the Folders in the next Level..Increase our count of the Folders in the Next folder level
            Next oSubfolder
            '5b) Doing Stuff for every file in current folder
                For Each oFile In oFolder.Files
                '''''''Doing Stuff for Each File here
                    If InStr(1, oFile.Name, ".xls") > 0 Then 'Option to select only if .xls ( or .xlsx or .xlsm ) type files
                    rCnt = rCnt + 1
                    celTL.Cells(rCnt, clmLvl).Offset(0, 1).Value = oFile.Name
                    On Error GoTo ErrHdlr 'In case problem opening file for example
                    'Set wbk = Workbooks.Open(oFile)
                    'wbk.Close SaveChanges:=True
                    Else: End If
                '''''''End Doing Stuff for Each File
    NxtoFile:   Next oFile ' Spring Point after error handler so as to go on to next File after the File action that errored
            '5Qc) should we have reached the end of the current level of Folders, we reset the level Column for output, and make the new Current Folders in Folder level Count equel to the next one, as we go ion now to Folders from the next level.
            If CurrentLvlCnt = 0 Then
            clmLvl = clmLvl + 1 'Set column position 1 to the left "down" the Folder Level Chain.
            Let CurrentLvlCnt = NxtLvlCnt 'So the current Folder Level count of Folders becomes that last counted.
            NxtLvlCnt = 0 'Next level of Folders currently are not in the Queue. This will be re counted for the next Folders as Sub Folders are added to the back of the Queue
            Else
            End If
            
        Loop 'queue.Count > 0 main loop for all Folders=====================================================================
    Application.ScreenUpdating = True
    MsgBox "All Excel Files processed", vbInformation
    ws.Columns("A:H").AutoFit
    Exit Sub 'Normal End for no Erriors
    Rem 6) 'Error handler section just put here for convenience
    ErrHdlr: 'Hopefully we know why we are here, and after informing can continue ( to next file )
    MsgBox prompt:="Error " & Err.Description & " with File " & oFile & ""
    On Error GoTo -1 'This needs to be done to reset the VBA exceptional error state of being. Otherwise VBA "thinks"" Errors are being handeled and will not respond again to the Error handler.
    On Error GoTo 0 ' Swiches off the current error handler. I do not really need to do this. But it is good practice so the error handler is only in place at the point where i next am expecting an error
    GoTo NxtoFile
    End Sub
    Last edited by DocAElstein; 01-23-2020 at 02:57 PM.
    ….If you are my competitor, I will try all I can to beat you. But if I do, I will not belittle you. I will Salute you, because without you, I am nothing.
    If you are my enemy, we will try to kick the fucking shit out of you…..
    Winston Churchill, 1939
    Save your Forum..._
    _...KILL A MODERATOR!!

  6. #16
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,439
    Rep Power
    10
    My codes
    Main Code
    Sub DoStuffInFoldersInFolderRecursion()
    And called Routine
    Sub LoopThroughEachFolderAndItsFile(

    Code:
    Option Explicit
    '
    'http://excelpoweruser.blogspot.de/2012/04/looping-through-folders-and-files-in.html     http://www.excelforum.com/excel-programming-vba-macros/1126751-get-value-function-loop-through-all-files-in-folder-and-its-subfolders.html#post4316662
    Sub DoStuffInFoldersInFolderRecursion() 'Main Procedure to call the Function  LoopThroughEachFolder(objFolder)
    Rem 1A) Some Worksheets and General Variables Info
    Dim ws As Worksheet: Set ws = ThisWorkbook.Worksheets.Item(1) 'Worksheets("RudyMSRQueue") 'CHANGE TO SUIT YOUR WORKSHEET
    Dim strDefPath As String: Let strDefPath = ThisWorkbook.Path ' Any Path to Folder to test this code! here we simply use the Path where the File with this code in is
    Dim strDefFldr As String: Let strDefFldr = "EileensFldr" 'Just for an initial suggestion
    Rem 2A) Get Folder Info ( Using Library Shell32 ( C:\WINDOWS\system32\SHELL32.dll ) Microsoft Shell Controls And Automation )
    Dim ShellApp  As Shell32.Shell ' The next two lines are the equivalent "Early Binding pair"
    Set ShellApp = New Shell32.Shell ''You will need to do select form VB Editor options .. Extras...then scroll down to  Microsoft Shell Controls And Automation  ...  and add a check
    Dim objWB As Object, strWB As String 'The  .BrowseForFolder Method appears either return a string of the Folder name you choose, or an object which is that chosen Folder, depending on how you declare the variable to put the retuned "thing" in
    Set objWB = ShellApp.BrowseForFolder(0, "Please choose a folder", 0, "" & strDefPath & "\" & strDefFldr & "") 'An Object of Folder type returned
    Let strWB = CStr(objWB) ' ! Cstr seems not to be necerssary
    
    Rem 3A )
    'Dim FSO As Object: Set FSO = CreateObject("Scripting.FileSystemObject")'Late Binding
    Dim FSO As Scripting.FileSystemObject 'Early Binding alternative  activate a reference to the Microsoft Scripting Runtime Library ( MSRL ) in the Tools References menu of VB Editor Options.
    Set FSO = New Scripting.FileSystemObject 'Create an Instance of the Class Scripting FileSystemObject
    Dim myFolder As Folder 'An Object from myFolder, can be an declared as Object also
    Set myFolder = FSO.GetFolder(strWB) 'Set the selected Folder to the Object Folder using this Method which takes as arbument the Full String Path
    
    Rem 4A )
    Dim rCnt As Long, CopyNumber As Long: Let rCnt = 1: Let CopyNumber = 1 '"Run progressin ( "down vertical" ) axis ( Row count for output ), "Down Folder chain to the right", The Count of the Copy of the called Procedue
    Dim celTL As Range: Set celTL = ws.Range("A1") 'Top left of where Licting should go
    celTL.Value = myFolder.Path: celTL.Offset(0, 1).Value = myFolder.Name: ws.Columns("A:C").AutoFit 'First output Row
    Call LoopThroughEachFolderAndItsFile(myFolder, celTL, rCnt, CopyNumber) 'Up until now we just got the initial Folder. Now we go to all sub folders  then all subfolders   then all subfolders.......
    Application.ScreenUpdating = True
    MsgBox "All Excel Files processed", vbInformation
    ws.Columns("A:H").AutoFit
    End Sub
    Rem 5A)
    Sub LoopThroughEachFolderAndItsFile(ByVal fldFldr As Folder, ByRef celTL As Range, ByRef rCnt As Long, ByVal CopyNumberFroNxtLvl As Long)  'In below function we have a nested loop to iterate each files also
    Dim myFldrs As Folder ''This is used continuously as the "steering" thing, that is to say each Sub Folder in Folder loops, in loops, in loops......etc
    Dim CopyNumber As Long 'equivalent to clmLvl in Rudis Q code
    If CopyNumber = 0 Then CopyNumber = CopyNumberFroNxtLvl 'If this variable in this Copy of the Routine has not been set then we have reached the next Copy for the First time, so set the variable so we have an indication ( number to the right or "down" Folder Chain
        '5Ab) Doing stuff for current Folder
        For Each myFldrs In fldFldr.SubFolders 'SubFolders collection used to get at all Sub Folders
        ''''''''Doing stuff for each Folder
        Let rCnt = rCnt + 1 + 1 ''At each folder we always move down a line, and a dd amm extra line  as a space between Folders ( The indication of the "column" or "down" to the right comes from the Copy Number of the Sub Procedure
        celTL.Cells(rCnt, 1).Value = myFldrs.Path: celTL.Cells(rCnt, CopyNumber).Offset(0, 2).Value = myFldrs.Name:   'Print out current Folder Path and Name in next free row.
        ''''''''End doing stuff for each Folder
        '5Ac) Doing stuff for current file.
        Dim oFile As File
                For Each oFile In myFldrs.Files 'Looking at all Files types initially '#####
                ''''''''Doing Stuff for Each File
        '            Dim Extension As String: Let Extension = Right(oFile.Name, (Len(oFile.Name) - (InStrRev(oFile.Name, ".")))) 'To get the bit just after the . dot.
        '                If Left(Extension, 3) = "xls" Then 'Check for your required File Type    #####
                    Let rCnt = rCnt + 1
                    celTL.Cells(rCnt, CopyNumber).Offset(0, 2).Value = oFile.Name ' Do your stuff here
        '                Dim wkb As Workbook
                         On Error GoTo ErrHdlr 'In case problem opening file for example
        '                Set wkb = Workbooks.Open(oFile)
        '                wkb.Close SaveChanges:=True
        '                Else 'Do not do stuff for a Bad Extension
        '                End If
                ''''''''End Doing Sttuff for Each File
    NxtoFile:   Next oFile ' Spring Point after error handler so as to go on to next File after the File action that errored
        Call LoopThroughEachFolderAndItsFile(myFldrs, celTL, rCnt, CopyNumber + 1) 'This is an example of recursion. It is actually very simple once you understand it. But it is just incredibly difficult to put in words. It is basically a Procedure that keeps calling itself as much as necessary as it goes "along",  "down", or "to the right" of the Path "roots". Every time it goes off calling itself VBA runs a copy of that Procedure. It "Stacks" all info carefully for each "Copy" Run and continues to do this "drilling" down as far as it must, in this case finding the Next Folder, and then the next Folder in that, then the next Folder in that, then the next Folder in that...I think you get the point! Each time VBA makes a copy of the Routine and you go into that. The calling Routine then "freezes at its current state and all variable keep there values. The "Frozen" Routine then re starts when the copy finishes
        Next
    Exit Sub 'Normal End for no Errors
    Rem 6 ) Error handler section just put here for convenience
    ErrHdlr: 'Hopefully we know why we are here, and after informing can continue ( to next file )
    MsgBox prompt:="Error " & Err.Description & " with File " & oFile & ""
    On Error GoTo -1 'This needs to be done to reset the VBA exceptional error state of being. Otherwise VBA "thinks" Errors are being handeled and will not respond again to the Error handler.
    On Error GoTo 0 ' Swiches off the current error handler. I do not really need to do this. But it is good practice so the error handler is only in place at the point where i next am expecting an error
    GoTo NxtoFile
    End Sub
    
    '
    '
    ''   http://www.excelforum.com/excel-programming-vba-macros/1126751-get-value-function-loop-through-all-files-in-folder-and-its-subfolders.html
    Last edited by DocAElstein; 01-23-2020 at 02:56 PM.
    ….If you are my competitor, I will try all I can to beat you. But if I do, I will not belittle you. I will Salute you, because without you, I am nothing.
    If you are my enemy, we will try to kick the fucking shit out of you…..
    Winston Churchill, 1939
    Save your Forum..._
    _...KILL A MODERATOR!!

  7. #17
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,439
    Rep Power
    10
    My codes ( again in color!! )
    Main Code
    Sub DoStuffInFoldersInFolderRecursion()
    And called Routine
    Sub LoopThroughEachFolderAndItsFile(

    Code:
    Option Explicit
    '
    'http://excelpoweruser.blogspot.de/2012/04/looping-through-folders-and-files-in.html     http://www.excelforum.com/excel-programming-vba-macros/1126751-get-value-function-loop-through-all-files-in-folder-and-its-subfolders.html#post4316662    http://www.excelfox.com/forum/f5/loop-through-files-in-a-folder-using-vba-1324/
    Sub DoStuffInFoldersInFolderRecursion() 'Main Procedure to call the Function  LoopThroughEachFolderAndItsFile(
    Rem 1A) Some Worksheets and General Variables Info
    Dim ws As Worksheet: Set ws = ThisWorkbook.Worksheets.Item(1) 'Worksheets("EFFldr") 'CHANGE TO SUIT YOUR WORKSHEET
    Rem 2A) Get Folder Info ( Using VBA Application.FileDialog(msoFileDialogFolderPicker) Property )
    Dim strWB As String
      With Application.FileDialog(msoFileDialogFolderPicker)
        .Title = "Folder Select "
        .AllowMultiSelect = False
            If .Show <> -1 Then
            Exit Sub
            End If
        Let strWB = .SelectedItems(1) & "\"
      End With
    
    Rem 3A )
    Dim FSO As Object: Set FSO = CreateObject("Scripting.FileSystemObject") 'Late Binding
    'Dim FSO As Scripting.FileSystemObject 'Early Binding alternative  activate a reference to the Microsoft Scripting Runtime Library ( MSRL ) in the Tools References menu of VB Editor Options.
    'Set FSO = New Scripting.FileSystemObject 'Create an Instance of the Class Scripting FileSystemObject
    Dim myFolder As Object 'An Object from myFolder, can be an declared as Dim myFolder As Folder also for Early Binding
    Set myFolder = FSO.GetFolder(strWB) 'Set the selected Folder to the Object Folder using this Method which takes as arbument the Full String Path
    
    Rem 4A )
    Dim rCnt As Long, CopyNumber As Long: Let rCnt = 1: Let CopyNumber = 1 '"Run progressin ( "down vertical" ) axis ( Row count for output ), "Down Folder chain to the right", The Count of the Copy of the called Procedue
    Dim celTL As Range: Set celTL = ws.Range("A1") 'Top left of where Licting should go
    celTL.Value = myFolder.Path: celTL.Offset(0, 1).Value = myFolder.Name: ws.Columns("A:C").AutoFit 'First output Row
    Call LoopThroughEachFolderAndItsFile(myFolder, celTL, rCnt, CopyNumber) 'Up until now we just got the initial Folder. Now we go to all sub folders  then all subfolders   then all subfolders.......
    Application.ScreenUpdating = True
    MsgBox "All Excel Files processed", vbInformation
    ws.Columns("A:H").AutoFit
    End Sub
    Rem 5A)
    Sub LoopThroughEachFolderAndItsFile(ByVal fldFldr As Object, ByRef celTL As Range, ByRef rCnt As Long, ByVal CopyNumberFroNxtLvl As Long)  'In below function we have a nested loop to iterate each files also
    Dim myFldrs As Object ''This is used continuously as the "steering" thing, that is to say each Sub Folder in Folder loops, in loops, in loops......etc   ....can be Dim myFldrs As Folder for early bindingDim CopyNumber As Long 'equivalent to clmLvl in Rudis Q code
    Dim CopyNumber As Long 'equivalent to clmLvl in Rudis Q code
    If CopyNumber = 0 Then CopyNumber = CopyNumberFroNxtLvl 'If this variable in this Copy of the Routine has not been set then we have reached the next Copy for the First time, so set the variable so we have an indication ( number to the right or "down" Folder Chain
        '5Ab) Doing stuff for current Folder
        For Each myFldrs In fldFldr.SubFolders 'SubFolders collection used to get at all Sub Folders
        ''''''''Doing stuff for each Folder
        Let rCnt = rCnt + 1 + 1 ''At each folder we always move down a line, and a dd amm extra line  as a space between Folders ( The indication of the "column" or "down" to the right comes from the Copy Number of the Sub Procedure
        celTL.Cells(rCnt, 1).Value = myFldrs.Path: celTL.Cells(rCnt, CopyNumber).Offset(0, 2).Value = myFldrs.Name:   'Print out current Folder Path and Name in next free row.
        ''''''''End doing stuff for each Folder
        '5Ac) Doing stuff for current file.
        Dim oFile As Object '  ... for early binding can Dim oFile As file
                For Each oFile In myFldrs.Files 'Looking at all Files types initially '#####
                ''''''''Doing Stuff for Each File
        '            Dim Extension As String: Let Extension = Right(oFile.Name, (Len(oFile.Name) - (InStrRev(oFile.Name, ".")))) 'To get the bit just after the . dot.
        '                If Left(Extension, 3) = "xls" Then 'Check for your required File Type    #####
                    Let rCnt = rCnt + 1
                    celTL.Cells(rCnt, CopyNumber).Offset(0, 2).Value = oFile.Name ' Do your stuff here
        '                Dim wkb As Workbook
                         On Error GoTo ErrHdlr 'In case problem opening file for example
        '                Set wkb = Workbooks.Open(oFile)
        '                wkb.Close SaveChanges:=True
        '                Else 'Do not do stuff for a Bad Extension
        '                End If
                ''''''''End Doing Sttuff for Each File
    NxtoFile:   Next oFile ' Spring Point after error handler so as to go on to next File after the File action that errored
        Call LoopThroughEachFolderAndItsFile(myFldrs, celTL, rCnt, CopyNumber + 1) 'This is an example of recursion. It is actually very simple once you understand it. But it is just incredibly difficult to put in words. It is basically a Procedure that keeps calling itself as much as necessary as it goes "along",  "down", or "to the right" of the Path "roots". Every time it goes off calling itself VBA runs a copy of that Procedure. It "Stacks" all info carefully for each "Copy" Run and continues to do this "drilling" down as far as it must, in this case finding the Next Folder, and then the next Folder in that, then the next Folder in that, then the next Folder in that...I think you get the point! Each time VBA makes a copy of the Routine and you go into that. The calling Routine then "freezes at its current state and all variable keep there values. The "Frozen" Routine then re starts when the copy finishes
        Next
    Exit Sub 'Normal End for no Errors
    Rem 6 ) Error handler section just put here for convenience
    ErrHdlr: 'Hopefully we know why we are here, and after informing can continue ( to next file )
    MsgBox prompt:="Error " & Err.Description & " with File " & oFile & ""
    On Error GoTo -1 'This needs to be done to reset the VBA exceptional error state of being. Otherwise VBA "thinks" Errors are being handeled and will not respond again to the Error handler.
    On Error GoTo 0 ' Swiches off the current error handler. I do not really need to do this. But it is good practice so the error handler is only in place at the point where i next am expecting an error
    GoTo NxtoFile
    End Sub
    Last edited by DocAElstein; 01-23-2020 at 02:56 PM.
    ….If you are my competitor, I will try all I can to beat you. But if I do, I will not belittle you. I will Salute you, because without you, I am nothing.
    If you are my enemy, we will try to kick the fucking shit out of you…..
    Winston Churchill, 1939
    Save your Forum..._
    _...KILL A MODERATOR!!

  8. #18
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,439
    Rep Power
    10
    Here is another Folder to try
    https://app.box.com/s/9e6xnb65fijjhl7bk0q6gzzriihkzibw

    Results from that for my Code:

    Using Excel 2007 32 bit
    Row\Col
    A
    B
    C
    D
    E
    F
    1
    H:\Excel0202015Jan2016\ExcelForum\wbSheetMaker\EFl dr1_1 EFldr1_1
    2
    3
    H:\Excel0202015Jan2016\ExcelForum\wbSheetMaker\EFl dr1_1\EFldr1_1_1 EFldr1_1_1
    4
    File1_1_1a.xlsx
    5
    File1_1_2b.xlsx
    6
    7
    H:\Excel0202015Jan2016\ExcelForum\wbSheetMaker\EFl dr1_1\EFldr1_1_2 EFldr1_1_2
    8
    File1_1_2a.xlsx
    9
    File1_1_2b.xlsx
    10
    11
    H:\Excel0202015Jan2016\ExcelForum\wbSheetMaker\EFl dr1_1\EFldr1_1_2\Fldr1_1_2_1 Fldr1_1_2_1
    12
    File1_1_2_1a.xlsx
    13
    File1_1_2_1b.xlsx
    14
    15
    H:\Excel0202015Jan2016\ExcelForum\wbSheetMaker\EFl dr1_1\EFldr1_1_2\Fldr1_1_2_1\Fldr1_1_2_1_1 Fldr1_1_2_1_1
    16
    File1_1_2_1_1a.xlsx
    17
    18
    H:\Excel0202015Jan2016\ExcelForum\wbSheetMaker\EFl dr1_1\EFldr1_1_2\Fldr1_1_2_1\Fldr1_1_2_1_2 Fldr1_1_2_1_2
    19
    File1_1_2_1_2a.xlsx
    20
    File1_1_2_1_2b.xlsx
    21
    22
    H:\Excel0202015Jan2016\ExcelForum\wbSheetMaker\EFl dr1_1\EFldr1_1_3 EFldr1_1_3
    23
    24
    H:\Excel0202015Jan2016\ExcelForum\wbSheetMaker\EFl dr1_1\EFldr1_1_3\Fldr1_1_3_1 Fldr1_1_3_1
    25
    26
    H:\Excel0202015Jan2016\ExcelForum\wbSheetMaker\EFl dr1_1\EFldr1_1_3\Fldr1_1_3_1\Flsr1_1_3_1_1 Flsr1_1_3_1_1
    27
    File1_1_3_1_1a.xlsx
    28
    EFFldr
    Last edited by DocAElstein; 01-23-2020 at 02:52 PM.
    ….If you are my competitor, I will try all I can to beat you. But if I do, I will not belittle you. I will Salute you, because without you, I am nothing.
    If you are my enemy, we will try to kick the fucking shit out of you…..
    Winston Churchill, 1939
    Save your Forum..._
    _...KILL A MODERATOR!!

  9. #19
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,439
    Rep Power
    10
    Results using this main Folder
    https://app.box.com/s/9e6xnb65fijjhl7bk0q6gzzriihkzibw
    using Rudi's code:


    Using Excel 2007 32 bit
    Row\Col
    A
    B
    C
    D
    E
    F
    1
    H:\Excel0202015Jan2016\ExcelForum\wbSheetMaker\EFl dr1_1 EFldr1_1
    2
    3
    H:\Excel0202015Jan2016\ExcelForum\wbSheetMaker\EFl dr1_1\EFldr1_1_1 EFldr1_1_1
    4
    File1_1_1a.xlsx
    5
    File1_1_2b.xlsx
    6
    7
    H:\Excel0202015Jan2016\ExcelForum\wbSheetMaker\EFl dr1_1\EFldr1_1_2 EFldr1_1_2
    8
    File1_1_2a.xlsx
    9
    File1_1_2b.xlsx
    10
    11
    H:\Excel0202015Jan2016\ExcelForum\wbSheetMaker\EFl dr1_1\EFldr1_1_3 EFldr1_1_3
    12
    13
    H:\Excel0202015Jan2016\ExcelForum\wbSheetMaker\EFl dr1_1\EFldr1_1_2\Fldr1_1_2_1 Fldr1_1_2_1
    14
    File1_1_2_1a.xlsx
    15
    File1_1_2_1b.xlsx
    16
    17
    H:\Excel0202015Jan2016\ExcelForum\wbSheetMaker\EFl dr1_1\EFldr1_1_3\Fldr1_1_3_1 Fldr1_1_3_1
    18
    19
    H:\Excel0202015Jan2016\ExcelForum\wbSheetMaker\EFl dr1_1\EFldr1_1_2\Fldr1_1_2_1\Fldr1_1_2_1_1 Fldr1_1_2_1_1
    20
    File1_1_2_1_1a.xlsx
    21
    22
    H:\Excel0202015Jan2016\ExcelForum\wbSheetMaker\EFl dr1_1\EFldr1_1_2\Fldr1_1_2_1\Fldr1_1_2_1_2 Fldr1_1_2_1_2
    23
    File1_1_2_1_2a.xlsx
    24
    File1_1_2_1_2b.xlsx
    25
    26
    H:\Excel0202015Jan2016\ExcelForum\wbSheetMaker\EFl dr1_1\EFldr1_1_3\Fldr1_1_3_1\Flsr1_1_3_1_1 Flsr1_1_3_1_1
    27
    File1_1_3_1_1a.xlsx
    28
    EFFldr
    Last edited by DocAElstein; 01-23-2020 at 02:53 PM.
    ….If you are my competitor, I will try all I can to beat you. But if I do, I will not belittle you. I will Salute you, because without you, I am nothing.
    If you are my enemy, we will try to kick the fucking shit out of you…..
    Winston Churchill, 1939
    Save your Forum..._
    _...KILL A MODERATOR!!

  10. #20
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,439
    Rep Power
    10
    Second Code for nelson
    Post 9
    http://www.excelfox.com/forum/showth...0070#post10070





    [Code]Sub IJAdjustKAddTotalAllWorksheet() ' http://www.excelfox.com/forum/showthread.php/2144-Code-Required-to-calculate-number-of-days-worked-normal-overtime-and-holiday-overtime?p=10060#post10060
    Rem 1) Workbooks Info.
    Dim Wb As Workbook ' Dim: For Object variabls: Address location to a "pointer". That has all the actual memory locations (addresses) of the various property values , and it holds all the instructions what / how to change them , should that be wanted later. That helped explain what occurs when passing an Object to a Call ed Fucntion or Sub Routine By Val ue. In such an occurance, VBA actually passes a copy of the pointer. So that has the effect of when you change things like properties on the local variable , then the changes are reflected in changes in the original object. (The copy pointer instructs how to change those values, at the actual address held in that pointer). That would normally be the sort of thing you would expect from passing by Ref erence. But as that copy pointer "dies" after the called routine ends, then any changes to the Addresses of the Object Properties in the local variable will not be reflected in the original pointer. So you cannot actually change the pointer.)
    Set Wb = ActiveWorkbook ' Set: Fill or partially Fill: Setting to a Class will involve the use of an extra New at this code line. I will then have an Object referred to as an instance of a Class. At this point I include information on my Pointer Pigeon hole for a distinct distinguishable usage of an Object of the Class. For the case of something such as a Workbook this instancing has already been done, and in addition some values are filled in specific memory locations which are also held as part of the information in the Pigeon Hole Pointer. We will have a different Pointer for each instance. In most excel versions we already have a few instances of Worksheets. Such instances Objects can be further used., - For this a Dim to the class will be necessary, but the New must be omitted at Set. I can assign as many variables that I wish to the same existing instance
    Dim wsStear As Worksheet ' Used for each Worksheet counting Tabs from left from 1 To Total
    Rem 2) varables for some totals
    Const TDays As Long = 30 'Total days just taken as 30 ' Long is very simple to handle, - final memory "size" type is known (123.456 and 000.001 have same "size" computer memory ) , and so a Address suggestion can be given for the next line when the variable is filled in. '( Long is a Big whole Number limit (-2,147,483,648 to 2,147,483,647) If you need some sort of validation the value should only be within the range of a Byte/Integer otherwise there's no point using anything but Long.--upon/after 32-bit, Integers (Short) need converted internally anyways, so a Long is actually faster. )
    Dim Dte As Date, DteNo As Long ' I am hoping Dte will sort out getting a date in a format that I can use the Weekday function to see what week day it is and get that as a nuumber to check for..
    Rem 3) Loop through worksheets and give some Totals
    Dim Cnt As Long ' Loop Bound variable count for going through all worksheets
    '3a) main Loop start============================================= ========
    For Cnt = 1 To Wb.Worksheets.Count ' The Worksheets collection Object Property returns the number of worksheet items in the Workbook
    Set wsStear = Wb.Worksheets.Item(Cnt) ' At each loop the variable is set to the current Worksheet counting from the Cnt'ths tab from left
    Dim lr As Long ' Used for last row number in column E
    Let lr = wsStear.Range("E" & Rows.Count & "").End(xlUp).Row ' The Range Object ( cell ) that is the last cell in the column of interest (CHOOSE a column typically that will always have a last Entry in any Data) ,( Row Number given by .Count Property applied to ( any Worksheet would do, so leaving unqualified is OK here, ) Spreadsheet Range Rows Property) has the Property .End ( argument "Looking back up" ) appled to it. This Returns a new Range ( cell ) object which is that of the first Range ( cell ) with something in it "looking back up" in the XL spreadsheet from that last Cell. Then the .Row Property is applied to return a long number equal to the Row number of that cell: Rows.Count is the very last row number in your Worksheet. It is different for earlier versions of Excel. The End(xlUp) is the same as pressing a Ctrl+UpArrow key combination. The final ".Row" returns the row where the cursor stops after moving up.
    Dim FstDtaCel As Range: Set FstDtaCel = wsStear.Range("A1") ' Worksheets Range(" ") Property used to return Range object of first cell in second row
    '3b) Data arrays from worksheet. We need columns E H I J .... Date ( Column E ) and Total hrs ( Column H ) are required to use in calculations
    Dim arrInNorm() As Variant, arrInOver() As Variant ' In the next lines the .Value2 or .value Property is applied a Range object which presents the Value or Value2 value or values in a single variable of appropriate type or a field of member Elements of varaint types.We are expecting the latter, so declare ( Dim ) a dynamic Array variable appropriately. It must be dynamic as its size will be defined at that assignment
    Let arrInNorm() = FstDtaCel.Offset(0, 8).Resize(lr, 1).Value2 ' I ' Normal Hrs ( Column I ) are needed as they must be set to zero for Holy ?? Holidays ?? Friday ??
    Let arrInOver() = FstDtaCel.Offset(0, 9).Resize(lr, 1).Value2 ' J ' Overtime ( Column J ) is needed as it will be changed and then used in calculations
    Dim arrTotHrs() As Variant ' ,' ## ' arrDteClr() As Variant
    Let arrTotHrs() = FstDtaCel.Offset(0, 7).Resize(lr, 1).Value [color=darkgreen]' H ' ' One thing you pick up when learning VBA programming is that referring to cells from one to another via an offset is both fundamental and efficient. That makes sense as Excel is all about using the offsets mentioned above. So like if you use them you can "cut out the middle man". ( The middle man here might be considered as, for example, in VBA, using extra variables for different Range objects: A fundamental thing to do with any cell ( or strictly speaking the Range object associated to a cell ) is the Range Item Property of any range Object, through which you can "get at" any other Range object. http://www.excelforum.com/showthread.php?t=1154829&page=13&p=4563838&highlight=#post4563838 ( It is often quicker than using a separate variable for each Range object
    Last edited by DocAElstein; 01-23-2020 at 02:53 PM.
    ….If you are my competitor, I will try all I can to beat you. But if I do, I will not belittle you. I will Salute you, because without you, I am nothing.
    If you are my enemy, we will try to kick the fucking shit out of you…..
    Winston Churchill, 1939
    Save your Forum..._
    _...KILL A MODERATOR!!

Similar Threads

  1. Tests and Notes on Range Referrencing
    By DocAElstein in forum Test Area
    Replies: 70
    Last Post: 02-20-2024, 01:54 AM
  2. Tests and Notes for EMail Threads
    By DocAElstein in forum Test Area
    Replies: 29
    Last Post: 11-15-2022, 04:39 PM
  3. Replies: 49
    Last Post: 03-20-2018, 04:09 PM
  4. Replies: 1
    Last Post: 02-14-2013, 12:09 PM
  5. List File name in folder to excel with images
    By Ryan_Bernal in forum Excel Help
    Replies: 2
    Last Post: 01-15-2013, 11:37 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •