Results 1 to 10 of 185

Thread: Appendix Thread 2. ( Codes for other Threads, HTML Tables, etc.)

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,319
    Rep Power
    10

    Post 22 Before ( BB Code )

    Post 22 Before ( BB Code )

    http://www.excelfox.com/forum/showth...0090#post10090


    Using Excel 2007 32 bit
    Row\Col
    C
    D
    E
    F
    G
    H
    I
    J
    1
    121
    TEAM LEADER
    21.Dec.16
    7:00
    18:00
    11:00
    9:00
    2:00
    2
    121
    TEAM LEADER
    22.Dec.16
    7:00
    18:00
    11:00
    9:00
    2:00
    3
    121
    TEAM LEADER
    23.Dec.16
    7:00
    15:00
    8:00
    9:00
    0:00
    4
    121
    TEAM LEADER
    24.Dec.16
    7:00
    18:00
    11:00
    9:00
    2:00
    5
    121
    TEAM LEADER
    25.Dec.16
    7:00
    18:00
    11:00
    9:00
    2:00
    6
    121
    TEAM LEADER
    26.Dec.16
    7:00
    18:00
    11:00
    9:00
    2:00
    7
    121
    TEAM LEADER
    27.Dec.16
    7:00
    17:00
    10:00
    9:00
    1:00
    8
    121
    TEAM LEADER
    28.Dec.16
    7:00
    18:00
    11:00
    9:00
    2:00
    9
    29.Dec.16
    10
    30.Dec.16
    11
    31.Dec.16
    12
    121
    TEAM LEADER
    1.Jan.17
    7:00
    18:00
    11:00
    9:00
    2:00
    13
    121
    TEAM LEADER
    2.Jan.17
    7:00
    18:00
    11:00
    9:00
    2:00
    14
    121
    TEAM LEADER
    3.Jan.17
    7:00
    18:00
    11:00
    9:00
    2:00
    15
    121
    TEAM LEADER
    4.Jan.17
    7:00
    18:00
    11:00
    9:00
    2:00
    16
    121
    TEAM LEADER
    5.Jan.17
    7:00
    18:00
    11:00
    9:00
    2:00
    17
    121
    TEAM LEADER
    6.Jan.17
    18
    121
    TEAM LEADER
    7.Jan.17
    7:00
    18:00
    11:00
    9:00
    2:00
    19
    121
    TEAM LEADER
    8.Jan.17
    7:00
    18:00
    11:00
    9:00
    2:00
    20
    121
    TEAM LEADER
    9.Jan.17
    21
    121
    TEAM LEADER
    10.Jan.17
    7:00
    18:00
    11:00
    9:00
    2:00
    22
    121
    TEAM LEADER
    11.Jan.17
    7:00
    18:00
    11:00
    9:00
    2:00
    23
    121
    TEAM LEADER
    12.Jan.17
    7:00
    18:00
    11:00
    9:00
    2:00
    24
    121
    TEAM LEADER
    13.Jan.17
    7:00
    18:00
    11:00
    9:00
    2:00
    25
    121
    TEAM LEADER
    14.Jan.17
    7:30
    17:30
    10:00
    9:00
    1:00
    26
    121
    TEAM LEADER
    15.Jan.17
    7:30
    17:30
    10:00
    9:00
    1:00
    27
    121
    TEAM LEADER
    16.Jan.17
    7:30
    17:30
    10:00
    9:00
    1:00
    28
    121
    TEAM LEADER
    17.Jan.17
    7:30
    17:30
    10:00
    9:00
    1:00
    29
    121
    TEAM LEADER
    18.Jan.17
    7:00
    18:00
    11:00
    9:00
    2:00
    30
    19.Jan.17
    31
    121
    TEAM LEADER
    20.Jan.17
    32
    33
    34
    Normal Overtime ----->
    Holiday Overtime ----->
    Worksheet: Post22Before121
    ….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. #2
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,319
    Rep Power
    10
    First macro attempt for this Thread
    https://www.excelfox.com/forum/showt...3203#post23203


    When you add things in the F___ column, then things happen as explained here: https://www.excelfox.com/forum/showt...ll=1#post23205

    _____ Workbook: FilTit.xlsm ( Using Excel 2010 32 bit )
    Row\Col A B C D E F G
    1 Fname FRegion FCountry Falan
    2 u
    3 rr sh
    4 ll Big
    5
    Worksheet: Sheet1





    The examples used in the explanation work on the data table in the next post



    Code:
    Option Explicit
    '  https://www.excelfox.com/forum/showthread.php/2922-VBA-Count-filtered-rows-in-the-table?p=23201&viewfull=1#post23201
    Private Sub Worksheet_Change(ByVal Target As Range)
    Rem 1 what cell changes don't interest me
     If Target.Cells.Count <> 1 Then Exit Sub '  More than one cell changed, for example by pasiting new range in
     If Target.Row = 1 Then Exit Sub '        '  Row 1 is always header so of no interst for adding data
     If Target.Value = "" Then Exit Sub '     '  If we empty a cell we don't want the macro to do anything
    Rem 2 find range to search
    Dim Hdr As String, HdRw() As Variant, Lc As Long, Lr As Long, Fc As Long, ClmsCnt As Long
     Let Hdr = Cells.Item(1, Target.Column).Value ' we get the header from the first row in the changed column
     Let Hdr = LCase(Mid(Hdr, 2))                ' take off the  F  at the start and change to lower case
     Let Lc = Cells.Item(1, Columns.Count).End(xlToLeft).Column  ' the last column in the worksheet that has something in the first row, so this will probably
     Let ClmsCnt = Cells.Item(1, Lc).CurrentRegion.Columns.Count '  Current region  is a square range that includes the cell its applied to and goes as far as there is a spreadsheet boundry of an empty column or row, so the column count of that range will likely tell us how many columns are in our table
     Let Fc = Lc - ClmsCnt + 1                                   ' This should get us the first column of out table
    Dim MtchRes As Variant
     Let MtchRes = Application.Match(Hdr, Cells.Item(1, Fc).Resize(1, ClmsCnt), 0)   '  Either this will return us an VBA error ( it won't actually error ) ,  or it will give a number of the "position along" of where it makes a match
        If IsError(MtchRes) Then MsgBox prompt:="I can't find " & Hdr & "": Exit Sub ' For the case of getting an VBA error returned I must have an incorrect header somewhere, maybe a typo in a header somewhere
    Dim SrchClm As Long: Let SrchClm = MtchRes + Fc - 1    '  This should give us the number of the column in the table that I want to search
     Let Lr = Cells.Item(Rows.Count, SrchClm).End(xlUp).Row ' This should return the last used row in that column
        If Cells.Item(Lr, SrchClm) = "" Then Let Lr = Cells.Item(Lr, SrchClm).End(xlUp).Row '  This sia bit of a bodge, and I am not sure yet why i nned this, but it appears that I first find the last row in the table if the last row is empty for this column.  Strange, but empirically it seems doing it again gets over this problem. I also saw that doing it again if I did get the correct last row with something in it, then doing it again will get me down to row 1.   So it looks like perhaps it initially gety the end of the table. That is OK if the column to search has a last table entry.  otherwise doing it again gets me down to the löast used row for that column
    Dim SrchRng As Range: Set SrchRng = Cells.Item(2, SrchClm).Resize(Lr - 1, 1) '  This will be the column range to search
    Dim arrSrch() As Variant: Let arrSrch() = SrchRng.Value '  gets an array of the search range
    Rem 3 Get array of matches by clever way that only Alan, The Fuhrer, knows about
    Dim arrSrchF() As Variant
     Let arrSrchF() = Evaluate("=IF({1},SEARCH(" & """" & Target.Value & """" & "," & SrchRng.Address & "))")
    Rem 4 Get results from arrHits()
    Dim TRws As Long, HitRws As Long, strHits As String
    Dim Cnt As Long   '      arrSrchF()  will look like this,  https://i.postimg.cc/gJQ121Wq/arr-Srch-F.jpg  , each element has something similar to the  .Match  result, so we can use that to see if we got a match or not
        For Cnt = 1 To UBound(arrSrchF(), 1)
            If IsError(arrSrchF(Cnt, 1)) Then
            ' if error than no hit
            Else
             Let strHits = strHits & arrSrch(Cnt, 1) & vbCr & vbLf  '  This gives the actual value of a hit, or rather adds it to a long text string for the output
            End If
            
        Next Cnt
     Let strHits = Left(strHits, Len(strHits) - 2)  ' This takes off the last  vbDr & vbLf  which we doin't need
    Rem 5 Final output
    Dim arrFnd() As String: Let arrFnd() = Split(strHits, vbCr & vbLf, -1, vbBinaryCompare) '  This splits the output string by the  line seperator, and returns a 1 dimansional array where each elemnt is effectively a matched row value.  The number of elements of this array will be a convenient way on the next line to get the numkber of row match results we got
     Let strHits = Hdr & " Filter by " & Target.Value & " will get " & UBound(arrFnd()) + 1 & " rows " & vbCr & vbLf & vbCr & vbLf & strHits & vbCr & vbLf
     Let strHits = strHits & vbCr & vbLf & "Total rows in " & Hdr & " column was " & Lr - 1
     MsgBox prompt:=strHits: Debug.Print strHits
    End Sub
    Attached Files Attached Files
    Last edited by DocAElstein; 08-22-2023 at 12:04 PM.

  3. #3
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,319
    Rep Power
    10
    Some extra notes for this Post
    https://www.excelfox.com/forum/showt...ll=1#post23399



    Code:
    Sub GenerateWorkbooksPerName()
        
        Const REPEATING_ROWS As Long = 6
        Const NAME_DELIMITER As String = " "
        
        Dim swb As Workbook: Set swb = ThisWorkbook
        Dim sws As Worksheet: Set sws = swb.Worksheets("CROSSACT")
        
        Dim FirstRow As Long: FirstRow = REPEATING_ROWS + 1
        
        With sws.UsedRange
            If .Rows.Count < FirstRow Then Exit Sub
        End With
        
        Application.ScreenUpdating = False
        
        sws.Copy
        
        Dim dwb As Workbook: Set dwb = Workbooks(Workbooks.Count)
        Dim dws As Worksheet: Set dws = dwb.Sheets(1)
        
        With dws.UsedRange
            .Resize(.Rows.Count - REPEATING_ROWS).Offset(REPEATING_ROWS).Clear
        End With
        
        Dim dfCell As Range: Set dfCell = dws.Cells(FirstRow, "A")
        
        Dim dFolderPath As String:
        dFolderPath = swb.Path & Application.PathSeparator
    
        Dim ndLen As Long: ndLen = Len(NAME_DELIMITER)
        
        Dim r As Long, dCount As Long, dFilePath As String, dName As String
        
        For r = FirstRow To sws.Cells(sws.Rows.Count, "A").End(xlUp).Row
            sws.Rows(r).Copy dfCell
            dName = CStr(sws.Cells(r, "A").Value) & NAME_DELIMITER _
                & CStr(sws.Cells(r, "B").Value)
            If Len(dName) > ndLen Then
                dws.Name = dName
                dFilePath = dFolderPath & dName & ".xlsx"
                Application.DisplayAlerts = False
                    dwb.SaveAs dFilePath, xlOpenXMLWorkbook
                Application.DisplayAlerts = True
                dCount = dCount + 1
            End If
        Next r
        
        dwb.Close SaveChanges:=False
        
        Application.ScreenUpdating = True
        
        MsgBox dCount & " workbook" & IIf(dCount = 1, "", "s") & " generated.", _
            IIf(dCount = 0, vbCritical, vbInformation)
        
    End Sub

    https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA
    https://www.youtube.com/watch?v=jTmVtPHtiTg&lc=Ugy_RiNN_kAqUvZ8W994AaABAg
    https://www.youtube.com/watch?v=QjEWAJ3d-jw&lc=UgxJLVpwY8fIla7G-pN4AaABAg.9BLeCWVhxdG9wgNsaS3Lp1
    https://www.youtube.com/watch?v=QjEWAJ3d-jw&lc=UgxJLVpwY8fIla7G-pN4AaABAg.9BLeCWVhxdG9wgR1EPUkhw
    https://www.youtube.com/watch?v=QjEWAJ3d-jw&lc=UgxJLVpwY8fIla7G-pN4AaABAg.9BLeCWVhxdG9wgNe_XC-jK
    https://www.youtube.com/watch?v=QjEWAJ3d-jw&lc=UgxJLVpwY8fIla7G-pN4AaABAg.9BLeCWVhxdG9wgNPOdiDuv
    https://www.youtube.com/watch?v=QjEWAJ3d-jw&lc=UgxJLVpwY8fIla7G-pN4AaABAg.9BLeCWVhxdG9wgN7AC7wAc
    https://www.youtube.com/watch?v=bs-urI_o8jo&lc=UgyBACXgNY4j_cHgH5J4AaABAg.9oTkVdzfqfm9wlhQrYJP 3M
    https://www.youtube.com/watch?v=bs-urI_o8jo&lc=UgxYgiEZuS9I3xkjJv54AaABAg
    https://www.youtube.com/watch?v=DVFFApHzYVk&lc=Ugyi578yhj9zShmhuPl4AaABAg
    https://www.youtube.com/watch?v=GqzeFYWjTxI&lc=UgxvxlnuTRWiV6MUZB14AaABAg
    https://www.youtube.com/watch?v=_8i1fVEi5WY&lc=Ugz0ptwE5J-2CpX4Lzh4AaABAg
    https://www.youtube.com/watch?v=0ltJS7uHfK4&lc=UgxoHAw8RwR7VmyVBUt4AaABAg.9C-br0lEl8V9xI0_6pCaR9
    https://www.youtube.com/watch?v=0ltJS7uHfK4&lc=Ugz5DDCMqmHLeEjUU8t4AaABAg.9bl7m03Onql9xI-ar3Z0ME
    https://www.youtube.com/watch?v=0ltJS7uHfK4&lc=UgxYnpd9leriPmc8rPd4AaABAg.9gdrYDocLIm9xI-2ZpVF-q
    https://www.youtube.com/watch?v=0ltJS7uHfK4&lc=UgyjoPLjNeIAOMVH_u94AaABAg.9id_Q3FO8Lp9xHyeYSuv 1I
    https://www.reddit.com/r/windowsxp/comments/pexq9q/comment/k81ybvj/?utm_source=reddit&utm_medium=web2x&context=3
    https://www.youtube.com/watch?v=bs-urI_o8jo&lc=UgxYgiEZuS9I3xkjJv54AaABAg
    https://www.youtube.com/watch?v=bs-urI_o8jo&lc=UgyBACXgNY4j_cHgH5J4AaABAg.9oTkVdzfqfm9wlhQrYJP 3M
    ttps://www.youtube.com/watch?v=LP9fz2DCMBE
    https://www.youtube.com/watch?v=LP9fz2DCMBE&lc=UgzbPgJUMCztIOQDym14AaABAg
    https://www.youtube.com/watch?v=LP9fz2DCMBE&lc=UgzbPgJUMCztIOQDym14AaABAg.9wdo_rWgxSH9wdpcYqrv p8
    ttps://www.youtube.com/watch?v=bFxnXH4-L1A
    https://www.youtube.com/watch?v=bFxnXH4-L1A&lc=UgxuODisjo6cvom7O-B4AaABAg.9w_AeS3JiK09wdi2XviwLG
    https://www.youtube.com/watch?v=bFxnXH4-L1A&lc=UgxBU39bTptFznDC1PJ4AaABAg
    ttps://www.youtube.com/watch?v=GqzeFYWjTxI
    https://www.youtube.com/watch?v=GqzeFYWjTxI&lc=UgwJnJDJ5JT8hFvibt14AaABAg
    https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA
    Last edited by DocAElstein; 11-30-2023 at 03:18 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. VBA to Reply All To Latest Email Thread
    By pkearney10 in forum Outlook Help
    Replies: 11
    Last Post: 12-22-2020, 11:15 PM
  2. Appendix Thread. Diet Protokol Coding Adaptions
    By DocAElstein in forum Test Area
    Replies: 6
    Last Post: 09-05-2019, 10:45 AM
  3. Replies: 19
    Last Post: 04-20-2019, 02:38 PM
  4. Search List of my codes
    By PcMax in forum Excel Help
    Replies: 6
    Last Post: 08-03-2014, 08:38 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
  •