Page 23 of 38 FirstFirst ... 13212223242533 ... LastLast
Results 221 to 230 of 380

Thread: Appendix Thread. ( Codes for other Threads, etc.) Event Coding Drpdown Data validation

  1. #221
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,521
    Rep Power
    10
    In Support of this Post question
    2020-02-15 15:08:06 https://excelribbon.tips.net/T009046...een_Dates.html Karim K.

    Determining Differences Between Dates


    From Allen Wyatt, here https://excelribbon.tips.net/T009046...een_Dates.html

    ….. When you are programming Excel macros, you should know that dates are stored internally, within variables, as serial numbers. The serial number represents the number of days elapsed since a starting "base date," specifically since 1 January 100. This means that you can perform math with the serial numbers, if desired. You can, for instance, find the number of days between two dates by simply subtracting the dates from each other.

    If you want to get fancier in your date calculations, you can use the DateDiff function. This function allows you, for instance, to determine the number of weeks or months between two dates. In order to use the function to find this type of information, you would do as follows:


    Code:
    iNumWeeks = DateDiff("ww", dFirstDate, dSecondDate)
    iNumMonths = DateDiff("m", dFirstDate, dSecondDate)
    The first line determines the number of weeks between the two dates, and the second determines the number of months between them.
    Remember that the DateDiff function is a macro (VBA) function, not a worksheet function. Excel handles a range of dates in worksheets that begin with January 1, 1900. In VBA, however, dates can begin (as already noted) in the year 100. That means that macros can handle a much larger range of dates, including dates prior to those handled natively by Excel……………..




    Example: : User inputs "2/15/2019" in cell (C4) - The next day it shows "1 Day/s" and so on.


    The following coding must go in the worksheets code module of the worksheet of interest:
    _1 Right Click Tab _2 Select Show Code or _ 3 Double Click on worksheet in VB Editor project Explorer .JPG : https://imgur.com/1xcWkQJ , https://imgur.com/oWS0uZ4
    Attachment 2748Attachment 2749


    In first worksheet Code Module
    Code:
    Option Explicit ' https://excelribbon.tips.net/T009046_Determining_Differences_Between_Dates.html  '   https://docs.microsoft.com/de-de/office/vba/language/reference/user-interface-help/datediff-function
    Public Sub Worksheet_Change(ByVal Target As Range)
        If Target.Column = 3 Then
        Dim rngC As Range: Set rngC = Me.Range("C2:C" & (Me.UsedRange.Row + Me.UsedRange.Rows.Count - 1) & "") ' (Bottom left of Usedrange + Row count in UsedRange) - 1 will give us the last row
        Dim rngStr As Range
            For Each rngStr In rngC
                Debug.Print rngStr.Value ' From VB Editor, Hit keys  Ctrl + g  to see the immediate window
                If rngStr <> "" Then
                Dim Vl As String: Let Vl = rngStr.Value
                    If Len(Vl) < 8 Then MsgBox Prompt:=Vl & " is too short for a date": GoTo Nxt
                    If Len(Vl) - Len(Replace(Vl, "/", "")) <> 2 Then MsgBox Prompt:="Don't have 2 ""/""s in " & Vl: GoTo Nxt
                Dim Dey As String, Munf As String, Jear As String
                Dim strSplt() As String: Let strSplt() = Split(Vl, "/", 3, vbBinaryCompare) ' https://imgur.com/1xcWkQJ
                 Let Dey = strSplt(1): Munf = strSplt(0): Jear = strSplt(2)
                Dim Dte As Date, strDte As String, LngDte As Long
                 Let strDte = Format(Dey & " " & Munf & " " & Jear, "dd mmmm yyyy"): Debug.Print strDte
                 Let Dte = CDate(strDte)
                 Let strDte = Format(Dey & " " & Munf & " " & Jear, "dd" & ", " & "mmmm" & ",  " & "yyyy"): Debug.Print strDte
                 Let LngDte = CLng(Dte) ' Allen Wyatt: When you are programming Excel macros, you should know that dates are stored internally, within variables, as serial numbers. The serial number represents the number of days elapsed since a starting "base date," specifically since 1 January 100. This means that you can perform math with the serial numbers, if desired. You can, for instance, find the number of days between two dates by simply subtracting the dates from each other.
                Dim LngNow As Long: Let LngNow = CLng(Now())
                ' https://excelribbon.tips.net/T009046_Determining_Differences_Between_Dates.html  '  https://docs.microsoft.com/de-de/office/vba/language/reference/user-interface-help/datediff-function
                Dim iNumDays As Long, iNumWeeks As Long, iNumMonths As Long
                 Let iNumDays = DateDiff("d", LngDte, LngNow) ' = LngNow-LngDte
                 Let iNumWeeks = DateDiff("w", LngDte, LngNow)
                 Let iNumMonths = DateDiff("m", LngDte, LngNow)
                 Let Application.EnableEvents = False
                 Let rngStr.Offset(0, 1).Value = iNumDays & " Days,  " & iNumWeeks & " Weeks,   and " & iNumMonths & " Months."
                 Let rngStr.Offset(0, 2).Value = strDte
                 Let Application.EnableEvents = True
                Else ' case empty cell
                End If
    Nxt:    Next rngStr
        Else ' No change in column 3 ( "C" )
        End If
    
    Me.Columns.AutoFit
    End Sub
    
    Note:
    You may need to adjust the coding a bit with a +1 or -1 somewhere to get the day count output exactly as you want it


    The above macro will start automatically when you add a date into column “C” , provided it has this sort of format
    2/15/2020
    ( Month/Day/Year )



    The following additional macro, will ensure that the worksheet is updated when the workbook is opened

    Macro in ThisWorkbook code module
    Code:
    Private Sub Workbook_Open()
     Call Tabelle1.Worksheet_Change(Worksheets.Item(1).Range("C2"))
    End Sub
    The above code module and coding therein can be seen by double clicking on the ThisWorkbook code module in the VB Editor explorer:
    Double Click on ThisWorkbook in VB Editor Explorer.jpg : https://imgur.com/Kls33SD
    Attachment 2747

    Note, In order to call our macro Public Sub Worksheet_Change(ByVal Target As Range) in this way, we have changed the more typically seen , default option of Private to Public in the first macro in the worksheets code module

    Here is a typical output
    _____ Workbook: KarimKAllenWyattDateDifferences.xlsm ( Using Excel 2007 32 bit )
    Row\Col
    B
    C
    D
    E
    F
    3
    4
    2/15/2020 2 Days, 0 Weeks, and 0 Months. 15, Februar, 2020
    5
    1/15/2020 33 Days, 4 Weeks, and 1 Months. 15, Januar, 2020
    6
    6
    7
    3/12/2019 342 Days, 48 Weeks, and 11 Months. 12, März, 2019
    8
    2/16/2020 1 Days, 0 Weeks, and 0 Months. 16, Februar, 2020
    9
    z
    Worksheet: Tabelle1




    KarimKAllenWyattDateDifferences.xlsm : https://app.box.com/s/ti0n1wj62hcd2qmhcg5kiqle1sya79ux







  2. #222
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,521
    Rep Power
    10
    In support of this postpost
    http://www.excelfox.com/forum/showth...ce-Excel/page8
    http://www.excelfox.com/forum/showth...age8#post12252
    ( see also here : http://www.excelfox.com/forum/showth...ll=1#post12147
    http://www.excelfox.com/forum/showth...ll=1#post12148 )



    First a "VBA" arrays type macro to count the total number of files with their extensions , then a "spreadsheet" type equivalent extended also to look at the color of the cells
    Code:
    Rem 1 Worksheets info
    Dim Ws As Worksheet: Set Ws = Me
    Dim Rng As Range: Set Rng = Ws.Range("D2:F264")
    Dim arrFiles() As Variant: Let arrFiles() = Rng.Value2
    Rem 2 File extension types
    Dim Ddl As Long, Sys As Long, Bin As Long, Cpa As Long, Vp As Long, Els As Long
    Rem 3 Looping
    Dim ClCnt As Long, RwCnt As Long
        For RwCnt = 1 To UBound(arrFiles(), 1)
            For ClCnt = 1 To UBound(arrFiles(), 2)
                If arrFiles(RwCnt, ClCnt) = "" Then
                ' Empty cell, so do nothing
                Else ' Time to look at cell value
                    If Left(arrFiles(RwCnt, ClCnt), 3) = "C:\" And InStr(4, arrFiles(RwCnt, ClCnt), ".", vbBinaryCompare) > 1 Then ' use some criteria to check we have a file path
                    ' Get the extension
                    Dim Xtn As String
                     Let Xtn = Mid(arrFiles(RwCnt, ClCnt), (InStr(4, arrFiles(RwCnt, ClCnt), ".", vbBinaryCompare) + 1))
                        Select Case Xtn
                         Case "sys", "SYS"
                          Let Sys = Sys + 1
                         Case "dll"
                          Let Ddl = Ddl + 1
                         Case "bin"
                          Let Bin = Bin + 1
                         Case "cpa"
                          Let Cpa = Cpa + 1
                         Case "vp"
                          Let Vp = Vp + 1
                         Case Else
                          Debug.Print "Case Else   " & arrFiles(RwCnt, ClCnt)
                          Let Els = Els + 1
                        End Select
                    Else ' not a file path
                    End If
                End If
            Next ClCnt
        Next RwCnt
    Rem 4 output
    
    Debug.Print "sys   " & Sys
    Debug.Print "ddl   " & Ddl
    Debug.Print "bin   " & Bin
    Debug.Print "cpa   " & Cpa
    Debug.Print "vp   " & Vp
    Debug.Print "els   " & Els
    
    End Sub
    
    
    Sub WotsANormalCellColor()
     Let Range("A1").Value = "AnyText"
     Debug.Print Range("A1").Font.Color & "   " & Range("A1").Font.ColorIndex '  we seee that   Color  for black or automatic is  0    ColorIndex  for black is 1  for automatic is   -4105
    End Sub
    
    
    
    
    ' The next code and the one  in the next post is the spreadsheet type equivalent extended also to look at the color of the cells
    Sub FileTypesHere()
    Rem 1 Worksheets info
    Dim Ws As Worksheet: Set Ws = Me
    Dim Rng As Range: Set Rng = Ws.Range("D2:F264")
    'Dim arrFiles() As Variant: Let arrFiles() = Rng.Value2
    Rem 2 File extension types
    Dim Ddl As Long, Sys As Long, Bin As Long, Cpa As Long, Vp As Long, Els As Long
    Dim Ddl2 As Long, Sys2 As Long, Bin2 As Long, Cpa2 As Long, Vp2 As Long, Els2 As Long
    Rem 3 Looping
    'Dim ClCnt As Long, RwCnt As Long
    Dim RngStr As Range ' a single cell to use as a stear element in the For Next loop
        For Each RngStr In Rng
    '    For RwCnt = 1 To UBound(arrFiles(), 1)
    '        For ClCnt = 1 To UBound(arrFiles(), 2)
                'If arrFiles(RwCnt, ClCnt) = "" Then
                If RngStr.Value = "" Then
                ' Empty cell, so do nothing
                Else ' Time to look at cell value
                    'If Left(arrFiles(RwCnt, ClCnt), 3) = "C:\" And InStr(4, arrFiles(RwCnt, ClCnt), ".", vbBinaryCompare) > 1 Then ' use some criteria to check we have a file path
                    If Left(RngStr.Value, 3) = "C:\" And InStr(4, RngStr.Value, ".", vbBinaryCompare) > 1 Then ' use some criteria to check we have a file path
                    ' Get the extension
                    Dim Xtn As String
                    'Let Xtn = Mid(arrFiles(RwCnt, ClCnt), (InStr(4, arrFiles(RwCnt, ClCnt), ".", vbBinaryCompare) + 1))
                     Let Xtn = Mid(RngStr.Value, (InStr(4, RngStr.Value, ".", vbBinaryCompare) + 1))
                        Select Case Xtn
                         Case "sys", "SYS"
                          Let Sys = Sys + 1: If RngStr.Font.Color <> 0 Then Let Sys2 = Sys2 + 1
                         Case "dll"
                          Let Ddl = Ddl + 1: If RngStr.Font.Color <> 0 Then Let Ddl2 = Ddl2 + 1
                         Case "bin"
                          Let Bin = Bin + 1:: If RngStr.Font.Color <> 0 Then Let Bin2 = Bin2 + 1
                         Case "cpa"
                          Let Cpa = Cpa + 1: If RngStr.Font.Color <> 0 Then Let Cpa2 = Cpa2 + 1
                         Case "vp"
                          Let Vp = Vp + 1: If RngStr.Font.Color <> 0 Then Let Vp2 = Vp2 + 1
                         Case Else
                          Debug.Print "Case Else   " & RngStr.Value
                          Let Els = Els + 1: If RngStr.Font.Color <> 0 Then Let Els2 = Els2 + 1
                        End Select
                    Else ' not a file path
                    End If
                End If
    '        Next ClCnt
    '    Next RwCnt
        Next RngStr
    Rem 4 output
    
    Debug.Print "sys   " & Sys & " (" & Sys2 & ")"
    Debug.Print "dll   " & Ddl & " (" & Ddl2 & ")"
    Debug.Print "bin   " & Bin & " (" & Bin2 & ")"
    Debug.Print "cpa   " & Cpa & " (" & Cpa2 & ")"
    Debug.Print "vp   " & Vp & " (" & Vp2 & ")"
    Debug.Print "els   " & Els & " (" & Els2 & ")"
    
    End Sub
    

  3. #223
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,521
    Rep Power
    10
    Some coding in support of this post
    http://www.excelfox.com/forum/showth...age8#post12252
    for worksheet "DDAllBefore"


    ( see also here : http://www.excelfox.com/forum/showth...ll=1#post12147
    http://www.excelfox.com/forum/showth...ll=1#post12148 )


    Code:
    Option Explicit
    Sub ColumnsE()
     Columns("E:E").SpecialCells(xlCellTypeConstants, xlTextValues + xlNumbers).Copy
     Paste Destination:=Range("E680")
    End Sub
    
    
    Sub FileTypesHere()
    Rem 1 Worksheets info
    Dim Ws As Worksheet: Set Ws = Me
    Dim Rng As Range: Set Rng = Ws.Range("F5:G670")
    'Dim arrFiles() As Variant: Let arrFiles() = Rng.Value2
    Rem 2 File extension types
    Dim Ddl As Long, Sys As Long, Bin As Long, Cpa As Long, Vp As Long, Els As Long
    Dim Inf As Long, Ini As Long, Cat As Long, Gpd As Long, Xml As Long, Gdl As Long
    Dim Ddl2 As Long, Sys2 As Long, Bin2 As Long, Cpa2 As Long, Vp2 As Long, Els2 As Long
    Dim Inf2 As Long, Ini2 As Long, Cat2 As Long, Gpd2 As Long, Xml2 As Long, Gdl2 As Long
    Dim Js As Long, Dpd As Long, Ppd As Long, Cab As Long, Bag As Long, Exe As Long
    Dim Js2 As Long, Dpd2 As Long, Ppd2 As Long, Cab2 As Long, Bag2 As Long, Exe2 As Long
    Dim Dpb As Long
    Dim Dpb2 As Long
    Rem 3 Looping
    'Dim ClCnt As Long, RwCnt As Long
    Dim RngStr As Range ' a single cell to use as a stear element in the For Next loop
        For Each RngStr In Rng
    '    For RwCnt = 1 To UBound(arrFiles(), 1)
    '        For ClCnt = 1 To UBound(arrFiles(), 2)
                'If arrFiles(RwCnt, ClCnt) = "" Then
                If RngStr.Value = "" Then
                ' Empty cell, so do nothing
                Else ' Time to look at cell value
                    'If Left(arrFiles(RwCnt, ClCnt), 3) = "C:\" And InStr(4, arrFiles(RwCnt, ClCnt), ".", vbBinaryCompare) > 1 Then ' use some criteria to check we have a file path
                    'If Left(RngStr.Value, 3) = "C:\" And InStr(4, RngStr.Value, ".", vbBinaryCompare) > 1 Then ' use some criteria to check we have a file path
                    If InStr(2, RngStr.Value, ".", vbBinaryCompare) > 1 Then  ' use some criteria to check we have a file path
                    ' Get the extension
                    Dim Xtn As String
                    'Let Xtn = Mid(arrFiles(RwCnt, ClCnt), (InStr(4, arrFiles(RwCnt, ClCnt), ".", vbBinaryCompare) + 1))
                     Let Xtn = Mid(RngStr.Value, (InStr(2, RngStr.Value, ".", vbBinaryCompare) + 1))
                        Select Case UCase(Xtn)
                         Case "SYS"
                          Let Sys = Sys + 1: If RngStr.Font.Color <> 0 Then Let Sys2 = Sys2 + 1
                         Case "DLL"
                          Let Ddl = Ddl + 1: If RngStr.Font.Color <> 0 Then Let Ddl2 = Ddl2 + 1
                         Case "BIN"
                          Let Bin = Bin + 1: If RngStr.Font.Color <> 0 Then Let Bin2 = Bin2 + 1
                         Case "CPA"
                          Let Cpa = Cpa + 1: If RngStr.Font.Color <> 0 Then Let Cpa2 = Cpa2 + 1
                         Case "VP"
                          Let Vp = Vp + 1: If RngStr.Font.Color <> 0 Then Let Vp2 = Vp2 + 1
                         ' Inf As Long, Ini As Long, Cat As Long, Gpd As Long, Xml As Long, Gdl As Long
                          Case "INF"
                          Let Inf = Inf + 1: If RngStr.Font.Color <> 0 Then Let Inf2 = Inf2 + 1
                         Case "INI"
                          Let Ini = Ini + 1: If RngStr.Font.Color <> 0 Then Let Ini2 = Ini2 + 1
                         Case "CAT"
                          Let Cat = Cat + 1: If RngStr.Font.Color <> 0 Then Let Cat2 = Cat2 + 1
                         Case "GPD"
                          Let Gpd = Gpd + 1: If RngStr.Font.Color <> 0 Then Let Gpd2 = Gpd2 + 1
                         Case "XML"
                          Let Xml = Xml + 1: If RngStr.Font.Color <> 0 Then Let Xml2 = Xml2 + 1
                         Case "GDL"
                          Let Gdl = Gdl + 1: If RngStr.Font.Color <> 0 Then Let Gdl2 = Gdl2 + 1
                         ' Js As Long, Dpd As Long, Ppd As Long, Cab As Long, Bag As Long, Exe As Long
                         Case "JS"
                          Let Js = Js + 1: If RngStr.Font.Color <> 0 Then Let Js2 = Js2 + 1
                         Case "DPD"
                          Let Dpd = Dpd + 1: If RngStr.Font.Color <> 0 Then Let Dpd2 = Dpd2 + 1
                         Case "PPD"
                          Let Ppd = Ppd + 1: If RngStr.Font.Color <> 0 Then Let Ppd2 = Ppd2 + 1
                         Case "CAB"
                          Let Cab = Cab + 1: If RngStr.Font.Color <> 0 Then Let Cab2 = Cab2 + 1
                         Case "BAG"
                          Let Bag = Bag + 1: If RngStr.Font.Color <> 0 Then Let Bag2 = Bag2 + 1
                         Case "EXE"
                          Let Exe = Exe + 1: If RngStr.Font.Color <> 0 Then Let Exe2 = Exe2 + 1
                         ' DPB
                         Case "DPB"
                          Let Dpb = Dpb + 1: If RngStr.Font.Color <> 0 Then Let Dpb2 = Dpb2 + 1
                         
                                              
                         Case Else
                          Debug.Print "Case Else   " & RngStr.Value
                          Let Els = Els + 1:: If RngStr.Font.Color <> 0 Then Let Els2 = Els2 + 1
                        End Select
                    Else ' not a file path
                    End If
                End If
    '        Next ClCnt
    '    Next RwCnt
        Next RngStr
    Rem 4 output
    
    Debug.Print "sys   " & Sys & " (" & Sys2 & ")"
    Debug.Print "dll   " & Ddl & " (" & Ddl2 & ")"
    Debug.Print "bin   " & Bin & " (" & Bin2 & ")"
    Debug.Print "cpa   " & Cpa & " (" & Cpa2 & ")"
    Debug.Print "vp   " & Vp & " (" & Vp2 & ")"
    Debug.Print "els   " & Els & " (" & Els2 & ")"
    ' Inf As Long, Ini As Long, Cat As Long, Gpd As Long, Xml As Long, Gdl As Long
    Debug.Print "inf   " & Inf & " (" & Inf2 & ")"
    Debug.Print "ini   " & Ini & " (" & Ini2 & ")"
    Debug.Print "cat   " & Cat & " (" & Cat2 & ")"
    Debug.Print "gpd   " & Gpd & " (" & Gpd2 & ")"
    Debug.Print "xml   " & Xml & " (" & Xml2 & ")"
    Debug.Print "gdl   " & Gdl & " (" & Gdl2 & ")"
    ' Js As Long, Dpd As Long, Ppd As Long, Cab As Long, Bag As Long, Exe As Long
    Debug.Print "js   " & Js & " (" & Js2 & ")"
    Debug.Print "dpd   " & Dpd & " (" & Dpd2 & ")"
    Debug.Print "cab   " & Cab & " (" & Cab2 & ")"
    Debug.Print "bag   " & Bag & " (" & Bag2 & ")"
    Debug.Print "ppd   " & Ppd & " (" & Ppd & ")"
    Debug.Print "exe   " & Exe & " (" & Exe2 & ")"
    ' DPB
    Debug.Print "dpb   " & Dpb & " (" & Dpb2 & ")"
    End Sub

  4. #224
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,521
    Rep Power
    10
    Some additional coding to help in this Post
    http://www.excelfox.com/forum/showth...page9post12255

    (VBA "arrays" version)
    Code:
    Option Explicit
    Private Sub FileTypesHereArrays()
    Rem 1 Worksheets info
    Dim Ws As Worksheet: Set Ws = Me
    Dim Rng As Range: Set Rng = Ws.Range("D4:E75")
    Dim arrFiles() As Variant: Let arrFiles() = Rng.Value2
    Rem 2 File extension types
    Dim Ddl As Long, Sys As Long, Bin As Long, Cpa As Long, Vp As Long, Els As Long
    Dim Bag As Long, Xml As Long, Js As Long, Gdl As Long, Cab As Long, Ini As Long, Cat As Long, Inf As Long, Pnf As Long, Gpd As Long, Exe As Long
    Rem 3 Looping
    Dim ClCnt As Long, RwCnt As Long
        For RwCnt = 1 To UBound(arrFiles(), 1)
            For ClCnt = 1 To UBound(arrFiles(), 2)
                If arrFiles(RwCnt, ClCnt) = "" Then
                ' Empty cell, so do nothing
                Else ' Time to look at cell value
    '                If Left(arrFiles(RwCnt, ClCnt), 3) = "C:\" And InStr(4, arrFiles(RwCnt, ClCnt), ".", vbBinaryCompare) > 1 Then ' use some criteria to check we have a file path
                    If InStr(2, arrFiles(RwCnt, ClCnt), ".", vbBinaryCompare) > 1 Then ' use some criteria to check we have a file path
                    ' Get the extension
                    Dim Xtn As String
                     Let Xtn = Mid(arrFiles(RwCnt, ClCnt), (InStr(2, arrFiles(RwCnt, ClCnt), ".", vbBinaryCompare) + 1))
                        Select Case UCase(Xtn)
                         Case "SYS"
                          Let Sys = Sys + 1
                         Case "DLL"
                          Let Ddl = Ddl + 1
                         Case "BIN"
                          Let Bin = Bin + 1
                         Case "CPA"
                          Let Cpa = Cpa + 1
                         Case "VP"
                          Let Vp = Vp + 1
                         'Dim Bag As Long, Xml As Long, Js As Long, Gdl As Long, Cab As Long, Ini As Long, Cat As Long
                         Case "BAG"
                          Let Bag = Bag + 1
                         Case "XML"
                          Let Xml = Xml + 1
                         Case "JS"
                          Let Js = Js + 1
                         Case "GDL"
                          Let Gdl = Gdl + 1
                         Case "CAB"
                          Let Cab = Cab + 1
                         Case "INI"
                          Let Ini = Ini + 1
                         Case "CAT"
                          Let Cat = Cat + 1
                         ' Inf As Long, Pnf As Long, Gpd As Long, Exe as long
                         Case "INF"
                          Let Inf = Inf + 1
                         Case "PNF"
                          Let Pnf = Pnf + 1
                         Case "GPD"
                          Let Gpd = Gpd + 1
                         Case "EXE"
                          Let Exe = Exe + 1
                         Case Else
                          Debug.Print "Case Else   " & arrFiles(RwCnt, ClCnt)
                          Let Els = Els + 1
                        End Select
                    Else ' not a file path
                    End If
                End If
            Next ClCnt
        Next RwCnt
    Rem 4 output
    Debug.Print "sys   " & Sys
    Debug.Print "dll   " & Ddl
    Debug.Print "bin   " & Bin
    Debug.Print "cpa   " & Cpa
    Debug.Print "vp   " & Vp
    Debug.Print "els   " & Els
    'Dim Bag As Long, Xml As Long, Js As Long, Gdl As Long, Cab As Long, Ini As Long, Cat As Long
    Debug.Print "bag   " & Bag
    Debug.Print "xml   " & Xml
    Debug.Print "js   " & Js
    Debug.Print "gdl   " & Gdl
    Debug.Print "cab   " & Cab
    Debug.Print "ini   " & Ini
    Debug.Print "cat   " & Cat
    ' Inf As Long, Pnf As Long, Gpd As Long, Exe as long
    Debug.Print "inf   " & Inf
    Debug.Print "pnf   " & Pnf
    Debug.Print "gpd   " & Gpd
    Debug.Print "exe   " & Exe
    Debug.Print "Total is  " & Sys + Ddl + Bin + Cpa + Vp + Bag + Xml + Js + Gdl + Cab + Ini + Cat + Inf + Pnf + Gpd + Exe
    End Sub

  5. #225
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,521
    Rep Power
    10
    In support of this post
    http://www.excelfox.com/forum/showth...page9post12255



    Code:
    '
    Sub CompareDriverFilesCommandInDeviceManager() '                         InDoubleDriverAllList()
    Rem 0
        If ActiveSheet.Name <> "PowerShell" Then
         MsgBox prompt:="Oops": Exit Sub
        Else
        End If
    Rem 1 Worksheets info
    Dim WsDMP As Worksheet, WsCmd As Worksheet
     Set WsDMP = Worksheets("DeviceManagerProperties"): Set WsCmd = Worksheets("PowerShell")
    
    Rem 2 Looking at each cell in the selection
    ' Random number between 3 and 56 to get color index for any matching file names (1 is black, 2 is white , up to 56 is other colors:  3 to 56   is like  (0 to 53)+3  Rnd gives like  0-.99999  so (Int(Rnd*54))+3  is what we want
    Dim ClrIdx As Long
     Randomize: Let ClrIdx = (Int(Rnd * 54)) + 3
    
    Dim SrchForCel As Range
        For Each SrchForCel In Selection ' Take each cell in selected range
        Dim CelVl As String: Let CelVl = SrchForCel.Value
            'If CelVl <> "" And Left(CelVl, 3) = "C:\" And InStr(4, CelVl, ".", vbBinaryCompare) > 1 Then ' use some criteria to check we have a file path
            If CelVl <> "" And InStr(4, CelVl, ".", vbBinaryCompare) > 1 Then  ' use some criteria to check we have a file and not a Folder name with a  .  in it
                If Len(CelVl) > (InStr(4, CelVl, ".", vbBinaryCompare) + 3) Then
                ' case a lot of characters after the  .  so we probably have a Folder name
                Else
                Dim FileNmeSrchFor As String
                 Let FileNmeSrchFor = Right(CelVl, (Len(CelVl)) - (InStrRev(CelVl, "\", -1, vbBinaryCompare))) ' Determine the file name as that looking from the right as many characters as (the total character number) - (the position looking from the right of a "\")
                Rem 3 We now should have a file name, so we look for it in worksheet  DDAllBefore
                Dim SrchRng As Range: Set SrchRng = Application.Range("=DeviceManagerProperties!D2:DeviceManagerProperties!F265")    '
                Dim FndCel As Range
                 Set FndCel = SrchRng.Find(what:=FileNmeSrchFor, After:=Application.Range("=DeviceManagerProperties!D2"), LookAt:=xlPart, searchorder:=xlNext, MatchCase:=False) '
                    If Not FndCel Is Nothing Then ' the range is set, so the file string has been found in a cell in  DDAllBefore
                    Rem 4 we have two matching cells
                     'Debug.Print FndCel.Value
                    '4b) color matching file names in each worksheet, we do the unecerssary activating and selecting so we can see what is going in
                     WsCmd.Activate: SrchForCel.Select
                     'Application.Wait (Now + TimeValue("00:00:01"))
                     'Let SrchForCel.Characters(((InStrRev(CelVl, "\", -1, vbBinaryCompare)) + 1), (Len(CelVl)) - (InStrRev(CelVl, "\", -1, vbBinaryCompare))).Font.ColorIndex = ClrIdx
                     Let SrchForCel.Font.ColorIndex = ClrIdx
                     WsDMP.Activate: FndCel.Select
                     'Application.Wait (Now + TimeValue("00:00:02"))
                     Let FndCel.Font.ColorIndex = ClrIdx
                    Else ' No match was found - the thing in the cell in
                    End If
                End If ' end of check that the string with a  .  in it was a file
            Else ' case no file string in cell
            End If
        Next SrchForCel
    End Sub
    

  6. #226
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,521
    Rep Power
    10
    Some additional coding to help in this Post
    http://www.excelfox.com/forum/showth...page9post12255

    ("spreadsheet interaction" version)



    Code:
    Private Sub FileTypesHereSpreadsheetInteraction()
    Rem 1 Worksheets info
    Dim Ws As Worksheet: Set Ws = Me
    Dim Rng As Range: Set Rng = Ws.Range("D4:E75")
    'Dim arrFiles() As Variant: Let arrFiles() = Rng.Value2
    Rem 2 File extension types
    Dim Ddl As Long, Sys As Long, Bin As Long, Cpa As Long, Vp As Long, Els As Long
    Dim Bag As Long, Xml As Long, Js As Long, Gdl As Long, Cab As Long, Ini As Long
    Dim Cat As Long, Inf As Long, Pnf As Long, Gpd As Long, Exe As Long
    Dim Ddl2 As Long, Sys2 As Long, Bin2 As Long, Cpa2 As Long, Vp2 As Long
    Dim Bag2 As Long, Xml2 As Long, Js2 As Long, Gdl2 As Long, Cab2 As Long, Ini2 As Long
    Dim Cat2 As Long, Inf2 As Long, Pnf2 As Long, Gpd2 As Long, Exe2 As Long
    Rem 3 Looping
    Dim ClCnt As Long, RwCnt As Long
    Dim rngStr As Range
        For Each rngStr In Rng
    '    For RwCnt = 1 To UBound(arrFiles(), 1)
    '        For ClCnt = 1 To UBound(arrFiles(), 2)
                'If arrFiles(RwCnt, ClCnt) = "" Then
                If rngStr.Value = "" Then
                ' Empty cell, so do nothing
                Else ' Time to look at cell value
    '                If Left(arrFiles(RwCnt, ClCnt), 3) = "C:\" And InStr(4, arrFiles(RwCnt, ClCnt), ".", vbBinaryCompare) > 1 Then ' use some criteria to check we have a file path
                    'If InStr(2, arrFiles(RwCnt, ClCnt), ".", vbBinaryCompare) > 1 Then ' use some criteria to check we have a file path
                    If InStr(2, rngStr.Value, ".", vbBinaryCompare) > 1 Then ' use some criteria to check we have a file path
                    ' Get the extension
                    Dim Xtn As String
                     'Let Xtn = Mid(arrFiles(RwCnt, ClCnt), (InStr(2, arrFiles(RwCnt, ClCnt), ".", vbBinaryCompare) + 1))
                     Let Xtn = Mid(rngStr.Value, (InStr(2, rngStr.Value, ".", vbBinaryCompare) + 1))
                        Select Case UCase(Xtn)
                         Case "SYS"
                          Let Sys = Sys + 1: If rngStr.Font.Color <> 0 Then Let Sys2 = Sys2 + 1
                         Case "DLL"
                          Let Ddl = Ddl + 1: If rngStr.Font.Color <> 0 Then Let Ddl2 = Ddl2 + 1
                         Case "BIN"
                          Let Bin = Bin + 1: If rngStr.Font.Color <> 0 Then Let Bin2 = Bin2 + 1
                         Case "CPA"
                          Let Cpa = Cpa + 1: If rngStr.Font.Color <> 0 Then Let Cpa2 = Cpa2 + 1
                         Case "VP"
                          Let Vp = Vp + 1: If rngStr.Font.Color <> 0 Then Let Vp2 = Vp2 + 1
                         'Dim Bag As Long, Xml As Long, Js As Long, Gdl As Long, Cab As Long, Ini As Long, Cat As Long
                         Case "BAG"
                          Let Bag = Bag + 1: If rngStr.Font.Color <> 0 Then Let Bag2 = Bag2 + 1
                         Case "XML"
                          Let Xml = Xml + 1: If rngStr.Font.Color <> 0 Then Let Xml2 = Xml2 + 1
                         Case "JS"
                          Let Js = Js + 1: If rngStr.Font.Color <> 0 Then Let Js2 = Js2 + 1
                         Case "GDL"
                          Let Gdl = Gdl + 1: If rngStr.Font.Color <> 0 Then Let Gdl2 = Gdl2 + 1
                         Case "CAB"
                          Let Cab = Cab + 1: If rngStr.Font.Color <> 0 Then Let Cab2 = Cab2 + 1
                         Case "INI"
                          Let Ini = Ini + 1: If rngStr.Font.Color <> 0 Then Let Ini2 = Ini2 + 1
                         Case "CAT"
                          Let Cat = Cat + 1: If rngStr.Font.Color <> 0 Then Let Cat2 = Cat2 + 1
                         ' Inf As Long, Pnf As Long, Gpd As Long, Exe as long
                         Case "INF"
                          Let Inf = Inf + 1: If rngStr.Font.Color <> 0 Then Let Inf2 = Inf2 + 1
                         Case "PNF"
                          Let Pnf = Pnf + 1: If rngStr.Font.Color <> 0 Then Let Pnf2 = Pnf2 + 1
                         Case "GPD"
                          Let Gpd = Gpd + 1: If rngStr.Font.Color <> 0 Then Let Gpd2 = Gpd2 + 1
                         Case "EXE"
                          Let Exe = Exe + 1: If rngStr.Font.Color <> 0 Then Let Exe2 = Exe2 + 1
                         Case Else
                          Debug.Print "Case Else   " & rngStr.Value ' arrFiles(RwCnt, ClCnt)
                          Let Els = Els + 1
                        End Select
                    Else ' not a file path
                    End If
                End If
    '        Next ClCnt
    '    Next RwCnt
        Next rngStr
    Rem 4 output
    Debug.Print "sys   " & Sys & " (" & Sys2 & ")"
    Debug.Print "dll   " & Ddl & " (" & Ddl2 & ")"
    Debug.Print "bin   " & Bin & " (" & Bin2 & ")"
    Debug.Print "cpa   " & Cpa & " (" & Cpa2 & ")"
    Debug.Print "vp   " & Vp & " (" & Vp2 & ")"
    Debug.Print "els   " & Els
    'Dim Bag As Long, Xml As Long, Js As Long, Gdl As Long, Cab As Long, Ini As Long, Cat As Long
    Debug.Print "bag   " & Bag & " (" & Bag2 & ")"
    Debug.Print "xml   " & Xml & " (" & Xml2 & ")"
    Debug.Print "js   " & Js & " (" & Js2 & ")"
    Debug.Print "gdl   " & Gdl & " (" & Gdl2 & ")"
    Debug.Print "cab   " & Cab & " (" & Cab2 & ")"
    Debug.Print "ini   " & Ini & " (" & Ini2 & ")"
    Debug.Print "cat   " & Cat & " (" & Cat2 & ")"
    ' Inf As Long, Pnf As Long, Gpd As Long, Exe as long
    Debug.Print "inf   " & Inf & " (" & Inf2 & ")"
    Debug.Print "pnf   " & Pnf & " (" & Pnf2 & ")"
    Debug.Print "gpd   " & Gpd & " (" & Gpd2 & ")"
    Debug.Print "exe   " & Exe & " (" & Exe2 & ")"
    Debug.Print "Total is  " & Sys + Ddl + Bin + Cpa + Vp + Bag + Xml + Js + Gdl + Cab + Ini + Cat + Inf + Pnf + Gpd + Exe
    End Sub

  7. #227
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,521
    Rep Power
    10

    ' Macro to color text of matching files in two worksheets

    In support of this Post

    http://www.excelfox.com/forum/showth...age9#post12263



    Macro to colour match file entries in the two worksheets,
    PowerShell
    and
    DDAllBefore


    Code:
    Option Explicit
    Sub CompareDriverFilesCommandInDoubleDriver()  '    DeviceManager() '                         InDoubleDriverAllList()
    Rem 0
        If ActiveSheet.Name <> "PowerShell" Then
         MsgBox prompt:="Oops": Exit Sub
        Else
        End If
    Rem 1 Worksheets info
    Dim WsDD As Worksheet, WsCmd As Worksheet
     Set WsDD = Worksheets("DDAllBefore"): Set WsCmd = Worksheets("PowerShell")
    
    Rem 2 Looking at each cell in the selection
    ' Random number between 3 and 56 to get color index for any matching file names (1 is black, 2 is white , up to 56 is other colors:  3 to 56   is like  (0 to 53)+3  Rnd gives like  0-.99999  so (Int(Rnd*54))+3  is what we want
    Dim ClrIdx As Long
     Randomize: Let ClrIdx = (Int(Rnd * 54)) + 3
    
    Dim SrchForCel As Range
        For Each SrchForCel In Selection ' Take each cell in selected range
        Dim CelVl As String: Let CelVl = SrchForCel.Value
            'If CelVl <> "" And Left(CelVl, 3) = "C:\" And InStr(4, CelVl, ".", vbBinaryCompare) > 1 Then ' use some criteria to check we have a file path
            If CelVl <> "" And InStr(4, CelVl, ".", vbBinaryCompare) > 1 Then  ' use some criteria to check we have a file and not a Folder name with a  .  in it
                If Len(CelVl) > (InStr(4, CelVl, ".", vbBinaryCompare) + 3) Then
                ' case a lot of characters after the  .  so we probably have a Folder name
                Else
                Dim FileNmeSrchFor As String
                 Let FileNmeSrchFor = Right(CelVl, (Len(CelVl)) - (InStrRev(CelVl, "\", -1, vbBinaryCompare))) ' Determine the file name as that looking from the right as many characters as (the total character number) - (the position looking from the right of a "\")
                Rem 3 We now should have a file name, so we look for it in worksheet  DDAllBefore
                Dim SrchRng As Range: Set SrchRng = Application.Range("=DDAllBefore!D5:DDAllBefore!G670")    '
                Dim FndCel As Range
                 Set FndCel = SrchRng.Find(what:=FileNmeSrchFor, After:=Application.Range("=DDAllBefore!D5"), LookAt:=xlPart, searchorder:=xlNext, MatchCase:=False) '
                    If Not FndCel Is Nothing Then ' the range is set, so the file string has been found in a cell in  DDAllBefore
                    Rem 4 we have two matching cells
                     'Debug.Print FndCel.Value
                    '4b) color matching file names in each worksheet, we do the unecerssary activating and selecting so we can see what is going in
                     WsCmd.Activate: SrchForCel.Select
                     'Application.Wait (Now + TimeValue("00:00:01"))
                     'Let SrchForCel.Characters(((InStrRev(CelVl, "\", -1, vbBinaryCompare)) + 1), (Len(CelVl)) - (InStrRev(CelVl, "\", -1, vbBinaryCompare))).Font.ColorIndex = ClrIdx
                     Let SrchForCel.Font.ColorIndex = ClrIdx
                     WsDD.Activate: FndCel.Select
                     'Application.Wait (Now + TimeValue("00:00:02"))
                     Let FndCel.Font.ColorIndex = ClrIdx
                    Else ' No match was found - the thing in the cell in
                    End If
                End If ' end of check that the string with a  .  in it was a file
            Else ' case no file string in cell
            End If
        Next SrchForCel
    End Sub
    

  8. #228
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,521
    Rep Power
    10

    list all file types , and ( those having coloured text)- those also appearing in DoubleDriver worksheet)

    ' In support of this excelfox post : http://www.excelfox.com/forum/showth...ge10#post12271
    ' File to list all file types , and (those also appearing in DoubleDriver worksheet, ( Worksheets "DDAllBefore" ) )




    Code:
    ' In support of this excelfox post : http://www.excelfox.com/forum/showthread.php/2408-Windows-10-and-Office-Excel/page10#post12271
    ' File to list all file types , and (those also appearing in DoubleDriver worksheet, ( Worksheets "DDAllBefore" ) )
    Private Sub FileTypesHereAndAlsoInDoubleDriver()
    Rem 1 Worksheets info
    Dim Ws As Worksheet: Set Ws = Worksheets("PowerShell") ' Me
    Dim Rng As Range: Set Rng = Ws.Range("D4:E75")
    'Dim arrFiles() As Variant: Let arrFiles() = Rng.Value2
    Rem 2 File extension types
    Dim Ddl As Long, Sys As Long, Bin As Long, Cpa As Long, Vp As Long, Els As Long
    Dim Bag As Long, Xml As Long, Js As Long, Gdl As Long, Cab As Long, Ini As Long
    Dim Cat As Long, Inf As Long, Pnf As Long, Gpd As Long, Exe As Long
    Dim Ddl2 As Long, Sys2 As Long, Bin2 As Long, Cpa2 As Long, Vp2 As Long
    Dim Bag2 As Long, Xml2 As Long, Js2 As Long, Gdl2 As Long, Cab2 As Long, Ini2 As Long
    Dim Cat2 As Long, Inf2 As Long, Pnf2 As Long, Gpd2 As Long, Exe2 As Long
    Rem 3 Looping
    Dim ClCnt As Long, RwCnt As Long
    Dim rngStr As Range
        For Each rngStr In Rng
    '    For RwCnt = 1 To UBound(arrFiles(), 1)
    '        For ClCnt = 1 To UBound(arrFiles(), 2)
                'If arrFiles(RwCnt, ClCnt) = "" Then
                If rngStr.Value = "" Then
                ' Empty cell, so do nothing
                Else ' Time to look at cell value
    '                If Left(arrFiles(RwCnt, ClCnt), 3) = "C:\" And InStr(4, arrFiles(RwCnt, ClCnt), ".", vbBinaryCompare) > 1 Then ' use some criteria to check we have a file path
                    'If InStr(2, arrFiles(RwCnt, ClCnt), ".", vbBinaryCompare) > 1 Then ' use some criteria to check we have a file path
                    If InStr(2, rngStr.Value, ".", vbBinaryCompare) > 1 Then ' use some criteria to check we have a file path
                    ' Get the extension
                    Dim Xtn As String
                     'Let Xtn = Mid(arrFiles(RwCnt, ClCnt), (InStr(2, arrFiles(RwCnt, ClCnt), ".", vbBinaryCompare) + 1))
                     Let Xtn = Mid(rngStr.Value, (InStr(2, rngStr.Value, ".", vbBinaryCompare) + 1))
                        Select Case UCase(Xtn)
                         Case "SYS"
                          Let Sys = Sys + 1: If rngStr.Font.Color <> 0 Then Let Sys2 = Sys2 + 1
                         Case "DLL"
                          Let Ddl = Ddl + 1: If rngStr.Font.Color <> 0 Then Let Ddl2 = Ddl2 + 1
                         Case "BIN"
                          Let Bin = Bin + 1: If rngStr.Font.Color <> 0 Then Let Bin2 = Bin2 + 1
                         Case "CPA"
                          Let Cpa = Cpa + 1: If rngStr.Font.Color <> 0 Then Let Cpa2 = Cpa2 + 1
                         Case "VP"
                          Let Vp = Vp + 1: If rngStr.Font.Color <> 0 Then Let Vp2 = Vp2 + 1
                         'Dim Bag As Long, Xml As Long, Js As Long, Gdl As Long, Cab As Long, Ini As Long, Cat As Long
                         Case "BAG"
                          Let Bag = Bag + 1: If rngStr.Font.Color <> 0 Then Let Bag2 = Bag2 + 1
                         Case "XML"
                          Let Xml = Xml + 1: If rngStr.Font.Color <> 0 Then Let Xml2 = Xml2 + 1
                         Case "JS"
                          Let Js = Js + 1: If rngStr.Font.Color <> 0 Then Let Js2 = Js2 + 1
                         Case "GDL"
                          Let Gdl = Gdl + 1: If rngStr.Font.Color <> 0 Then Let Gdl2 = Gdl2 + 1
                         Case "CAB"
                          Let Cab = Cab + 1: If rngStr.Font.Color <> 0 Then Let Cab2 = Cab2 + 1
                         Case "INI"
                          Let Ini = Ini + 1: If rngStr.Font.Color <> 0 Then Let Ini2 = Ini2 + 1
                         Case "CAT"
                          Let Cat = Cat + 1: If rngStr.Font.Color <> 0 Then Let Cat2 = Cat2 + 1
                         ' Inf As Long, Pnf As Long, Gpd As Long, Exe as long
                         Case "INF"
                          Let Inf = Inf + 1: If rngStr.Font.Color <> 0 Then Let Inf2 = Inf2 + 1
                         Case "PNF"
                          Let Pnf = Pnf + 1: If rngStr.Font.Color <> 0 Then Let Pnf2 = Pnf2 + 1
                         Case "GPD"
                          Let Gpd = Gpd + 1: If rngStr.Font.Color <> 0 Then Let Gpd2 = Gpd2 + 1
                         Case "EXE"
                          Let Exe = Exe + 1: If rngStr.Font.Color <> 0 Then Let Exe2 = Exe2 + 1
                         Case Else
                          Debug.Print "Case Else   " & rngStr.Value ' arrFiles(RwCnt, ClCnt)
                          Let Els = Els + 1
                        End Select
                    Else ' not a file path
                    End If
                End If
    '        Next ClCnt
    '    Next RwCnt
        Next rngStr
    Rem 4 output
    Debug.Print "sys   " & Sys & " (" & Sys2 & ")"
    Debug.Print "dll   " & Ddl & " (" & Ddl2 & ")"
    Debug.Print "bin   " & Bin & " (" & Bin2 & ")"
    Debug.Print "cpa   " & Cpa & " (" & Cpa2 & ")"
    Debug.Print "vp   " & Vp & " (" & Vp2 & ")"
    Debug.Print "els   " & Els
    'Dim Bag As Long, Xml As Long, Js As Long, Gdl As Long, Cab As Long, Ini As Long, Cat As Long
    Debug.Print "bag   " & Bag & " (" & Bag2 & ")"
    Debug.Print "xml   " & Xml & " (" & Xml2 & ")"
    Debug.Print "js   " & Js & " (" & Js2 & ")"
    Debug.Print "gdl   " & Gdl & " (" & Gdl2 & ")"
    Debug.Print "cab   " & Cab & " (" & Cab2 & ")"
    Debug.Print "ini   " & Ini & " (" & Ini2 & ")"
    Debug.Print "cat   " & Cat & " (" & Cat2 & ")"
    ' Inf As Long, Pnf As Long, Gpd As Long, Exe as long
    Debug.Print "inf   " & Inf & " (" & Inf2 & ")"
    Debug.Print "pnf   " & Pnf & " (" & Pnf2 & ")"
    Debug.Print "gpd   " & Gpd & " (" & Gpd2 & ")"
    Debug.Print "exe   " & Exe & " (" & Exe2 & ")"
    Debug.Print "Total is  " & Sys + Ddl + Bin + Cpa + Vp + Bag + Xml + Js + Gdl + Cab + Ini + Cat + Inf + Pnf + Gpd + Exe
    End Sub
    
    
    

  9. #229
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,521
    Rep Power
    10
    In support of this post
    http://www.excelfox.com/forum/showth...ge11#post12276


    Code:
    Option Explicit
    Private Sub FileTypesHereArrays()
    Rem 1 Worksheets info
    Dim Ws As Worksheet: Set Ws = Me
    Dim Rng As Range: Set Rng = Ws.Range("D4:E180")
    Dim arrFiles() As Variant: Let arrFiles() = Rng.Value2
    Rem 2 File extension types
    Dim Ddl As Long, Sys As Long, Bin As Long, Cpa As Long, Vp As Long, Els As Long
    Dim Bag As Long, Xml As Long, Js As Long, Gdl As Long, Cab As Long, Ini As Long
    Dim Cat As Long, Inf As Long, Pnf As Long, Gpd As Long, Exe As Long
    Dim Sam As Long
    Rem 3 Looping
    Dim ClCnt As Long, RwCnt As Long
        For RwCnt = 1 To UBound(arrFiles(), 1)
            For ClCnt = 1 To UBound(arrFiles(), 2)
                If arrFiles(RwCnt, ClCnt) = "" Then
                ' Empty cell, so do nothing
                Else ' Time to look at cell value
    '                If Left(arrFiles(RwCnt, ClCnt), 3) = "C:\" And InStr(4, arrFiles(RwCnt, ClCnt), ".", vbBinaryCompare) > 1 Then ' use some criteria to check we have a file path
                    If InStr(2, arrFiles(RwCnt, ClCnt), ".", vbBinaryCompare) > 1 Then ' use some criteria to check we have a file path
                        Dim Xtn As String: Let Xtn = Mid(arrFiles(RwCnt, ClCnt), (InStr(2, arrFiles(RwCnt, ClCnt), ".", vbBinaryCompare) + 1)) ' this will give the text starting from after the first  dot  .
                        ' this next section catches single  .  things
                        If Len(arrFiles(RwCnt, ClCnt)) - Len(Replace(arrFiles(RwCnt, ClCnt), ".", "")) = 1 Then ' case a single  .
                            Select Case UCase(Xtn)
                             Case "SYS"
                              Let Sys = Sys + 1
                             Case "DLL"
                              Let Ddl = Ddl + 1
                             Case "BIN"
                              Let Bin = Bin + 1
                             Case "CPA"
                              Let Cpa = Cpa + 1
                             Case "VP"
                              Let Vp = Vp + 1
                             'Dim Bag As Long, Xml As Long, Js As Long, Gdl As Long, Cab As Long, Ini As Long, Cat As Long
                             Case "BAG"
                              Let Bag = Bag + 1
                             Case "XML"
                              Let Xml = Xml + 1
                             Case "JS"
                              Let Js = Js + 1
                             Case "GDL"
                              Let Gdl = Gdl + 1
                             Case "CAB"
                              Let Cab = Cab + 1
                             Case "INI"
                              Let Ini = Ini + 1
                             Case "CAT"
                              Let Cat = Cat + 1
                             ' Inf As Long, Pnf As Long, Gpd As Long, Exe as long
                             Case "INF"
                              Let Inf = Inf + 1
                             Case "PNF"
                              Let Pnf = Pnf + 1
                             Case "GPD"
                              Let Gpd = Gpd + 1
                             Case "EXE"
                              Let Exe = Exe + 1
                             ' sam
                             Case "SAM"
                              Let Sam = Sam + 1
                             Case Else
                              Debug.Print "Case Else for single ""  .   ""    " & arrFiles(RwCnt, ClCnt)
                              Let Els = Els + 1
                            End Select
                        ElseIf Len(arrFiles(RwCnt, ClCnt)) - Len(Replace(arrFiles(RwCnt, ClCnt), ".", "")) = 2 Then ' a thing like  hidscanner.dll.mui  or  sdstor.sys.mui
                        ' this next section catches double  .  .  things
                        Dim DllMui As Long, SysMui As Long, Els2 As Long
                            Select Case UCase(Xtn)
                             Case "DLL.MUI"
                              Let DllMui = DllMui + 1
                             Case "SYS.MUI"
                              Let SysMui = SysMui + 1
                             Case Else
                              Debug.Print "Case Else for double ""  .    .  ""    " & arrFiles(RwCnt, ClCnt)
                              Let Els2 = Els2 + 1
                            End Select
                        ElseIf Len(arrFiles(RwCnt, ClCnt)) - Len(Replace(arrFiles(RwCnt, ClCnt), ".", "")) > 2 Then
                        ' this section catches strings with dots more than 2
                        Dim LtsDts As Long
                         Debug.Print "More than 2 dots   --  " & arrFiles(RwCnt, ClCnt)
                         Let LtsDts = LtsDts + 1
                        End If
                    Else ' not a file, ( well no  .   in it anyway )
                    Dim Fldr As Long
                     Debug.Print "Folder?    " & arrFiles(RwCnt, ClCnt)
                     Let Fldr = Fldr + 1
                    End If
                End If
            Next ClCnt
        Next RwCnt
    Rem 4 output
    Debug.Print "sys       " & Sys
    Debug.Print "dll       " & Ddl
    Debug.Print "bin       " & Bin
    Debug.Print "cpa       " & Cpa
    Debug.Print "vp       " & Vp
    Debug.Print "Else1     " & Els
    'Dim Bag As Long, Xml As Long, Js As Long, Gdl As Long, Cab As Long, Ini As Long, Cat As Long
    Debug.Print "bag       " & Bag
    Debug.Print "xml       " & Xml
    Debug.Print "js       " & Js
    Debug.Print "gdl       " & Gdl
    Debug.Print "cab       " & Cab
    Debug.Print "ini       " & Ini
    Debug.Print "cat       " & Cat
    ' Inf As Long, Pnf As Long, Gpd As Long, Exe as long
    Debug.Print "inf       " & Inf
    Debug.Print "pnf       " & Pnf
    Debug.Print "gpd       " & Gpd
    Debug.Print "exe       " & Exe
    ' sam
    Debug.Print "sam       " & Sam
    ' Dim DllMui As Long, SysMui As Long, Els2 As Long
    Debug.Print "dll.mui   " & DllMui
    Debug.Print "sys.mui   " & SysMui
    Debug.Print "Else2     " & Els2
    Debug.Print "Total files is  " & Els + Sys + Ddl + Bin + Cpa + Vp + Bag + Xml + Js + Gdl + Cab + Ini + Cat + Inf + Pnf + Gpd + Exe + Els2 + DllMui + SysMui + Sam
    Debug.Print "Total Folders is    " & Fldr
    Debug.Print "Total things with more than 2 dots is  " & LtsDts
    End Sub
    

  10. #230
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,521
    Rep Power
    10
    In support of this post:
    http://www.excelfox.com/forum/showth...ge14#post12319


    Code:
    Sub FileTypesHereInDeviceManagerProperties()
    Rem 1 Worksheets info
    Dim Ws As Worksheet: Set Ws = Me
    Dim Rng As Range: Set Rng = Ws.Range("D2:F264")
    'Dim arrFiles() As Variant: Let arrFiles() = Rng.Value2
    Rem 2 File extension types
    Dim Ddl As Long, Sys As Long, Bin As Long, Cpa As Long, Vp As Long, Els As Long
    Dim Ddl2 As Long, Sys2 As Long, Bin2 As Long, Cpa2 As Long, Vp2 As Long, Els2 As Long
    Rem 3 Looping
    'Dim ClCnt As Long, RwCnt As Long
    Dim rngStr As Range ' a single cell to use as a stear element in the For Next loop
        For Each rngStr In Rng
    '    For RwCnt = 1 To UBound(arrFiles(), 1)
    '        For ClCnt = 1 To UBound(arrFiles(), 2)
                'If arrFiles(RwCnt, ClCnt) = "" Then
                If rngStr.Value = "" Then
                ' Empty cell, so do nothing
                Else ' Time to look at cell value
                    'If Left(arrFiles(RwCnt, ClCnt), 3) = "C:\" And InStr(4, arrFiles(RwCnt, ClCnt), ".", vbBinaryCompare) > 1 Then ' use some criteria to check we have a file path
                    If Left(rngStr.Value, 3) = "C:\" And InStr(4, rngStr.Value, ".", vbBinaryCompare) > 1 Then ' use some criteria to check we have a file path
                    ' Get the extension
                    Dim Xtn As String
                    'Let Xtn = Mid(arrFiles(RwCnt, ClCnt), (InStr(4, arrFiles(RwCnt, ClCnt), ".", vbBinaryCompare) + 1))
                     Let Xtn = Mid(rngStr.Value, (InStr(4, rngStr.Value, ".", vbBinaryCompare) + 1))
                        Select Case UCase(Xtn)
                         Case "SYS"
                          Let Sys = Sys + 1: If rngStr.Font.Color <> 0 Then Let Sys2 = Sys2 + 1
                         Case "DLL"
                          Let Ddl = Ddl + 1: If rngStr.Font.Color <> 0 Then Let Ddl2 = Ddl2 + 1
                         Case "BIN"
                          Let Bin = Bin + 1: If rngStr.Font.Color <> 0 Then Let Bin2 = Bin2 + 1
                         Case "CPA"
                          Let Cpa = Cpa + 1: If rngStr.Font.Color <> 0 Then Let Cpa2 = Cpa2 + 1
                         Case "VP"
                          Let Vp = Vp + 1: If rngStr.Font.Color <> 0 Then Let Vp2 = Vp2 + 1
                         Case Else
                          Debug.Print "Case Else   " & rngStr.Value
                          Let Els = Els + 1: If rngStr.Font.Color <> 0 Then Let Els2 = Els2 + 1
                        End Select
                    Else ' not a file path
                    End If
                End If
    '        Next ClCnt
    '    Next RwCnt
        Next rngStr
    Rem 4 output
    
    Debug.Print "sys   " & Sys & " (" & Sys2 & ")"
    Debug.Print "dll   " & Ddl & " (" & Ddl2 & ")"
    Debug.Print "bin   " & Bin & " (" & Bin2 & ")"
    Debug.Print "cpa   " & Cpa & " (" & Cpa2 & ")"
    Debug.Print "vp   " & Vp & " (" & Vp2 & ")"
    Debug.Print "els   " & Els & " (" & Els2 & ")"
    
    End Sub
    

Similar Threads

  1. Replies: 189
    Last Post: 02-06-2025, 02:53 PM
  2. Replies: 293
    Last Post: 09-24-2020, 01:53 AM
  3. Appendix Thread. Diet Protokol Coding Adaptions
    By DocAElstein in forum Test Area
    Replies: 6
    Last Post: 09-05-2019, 10:45 AM
  4. Restrict data within the Cell (Data Validation)
    By dritan0478 in forum Excel Help
    Replies: 1
    Last Post: 07-27-2017, 09:03 PM

Posting Permissions

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