Generate a list depending on date entered
Closed
                    
        
                    shootingfish
    
        
                    Posts
            
                
            14
                
                            Registration date
            Sunday February  6, 2011
                            Status
            Member
                            Last seen
            September  1, 2011
            
                -
                            Mar 17, 2011 at 06:53 AM
                        
rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 - Mar 22, 2011 at 07:02 AM
        rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 - Mar 22, 2011 at 07:02 AM
        Related:         
- Generate a list depending on date entered
- Counter strike 1.6 cheats list - Guide
- Amd crossfire gpu list - Guide
- How to change your best friends list on snapchat to 3 - Guide
- Epic games free games list - Guide
- How to enter @ on a laptop - Guide
1 response
                
        
                    rizvisa1
    
        
                    Posts
            
                
            4478
                
                            Registration date
            Thursday January 28, 2010
                            Status
            Contributor
                            Last seen
            May  5, 2022
            
            
                    766
    
    
                    
Mar 18, 2011 at 10:19 AM
    Mar 18, 2011 at 10:19 AM
                        
                    How familiar are you with macro?
                
                
             
        
    
    
    
    
Mar 21, 2011 at 04:00 AM
Mar 21, 2011 at 10:49 AM
Goto to Diary sheet
Paste this code
Private Sub Worksheet_Change(ByVal Target As Range) If (Target.Address <> "$C$2") Then Exit Sub If Target.Value = vbNullString Then Exit Sub If IsDate(Target) Then Application.EnableEvents = False Call doLocateMovement(Target.Value) Application.EnableEvents = True Else MsgBox "Please enter a valid date.", vbCritical, "Invalid Date" Application.EnableEvents = False Target = vbNullString Application.EnableEvents = True End If End Sub Private Sub doLocateMovement(sDate As String) Dim lTgtRow As Long Dim rngTarget As Range Dim sMove As String Dim sDiary As String Dim iCol As Integer Dim iMaxCol As Integer Dim iJobTitleRow As Integer Dim iNameRow As Integer Dim iRotationRow As Integer Dim dicJobTitle As Object Dim sJobTitle As String Dim sName As String Dim sRotation As String Dim sReasonCode As String Dim vOption As Variant Dim arrRecGroup As Variant Dim arrRecDetail As Variant Dim lRecGroup As Long Dim lRecDetail As Long Dim lDetailRow As Long iJobTitleRow = 4 iNameRow = 5 iRotationRow = 6 sMoveSheet = "Movements" sDiary = "Diary" With Sheets(sMoveSheet) ' locate the date text on column A lTgtRow = getItemRowLocation(sDate, .Name, Range("A:A")) If (lTgtRow < 1) _ Then MsgBox sDate & " not found in sheet " & .Name Exit Sub End If ' locate last column used on the row located iMaxCol = getLastColumn(.Name, Range(Cells(1, "B"), Cells(Rows.Count, Columns.Count))) If (iMaxCol = 0) _ Then MsgBox "No record found for date " & sDate, vbInformation, "Record Not Found" Exit Sub End If Set dicJobTitle = CreateObject("Scripting.Dictionary") For iCol = 2 To iMaxCol If (.Cells(lTgtRow, iCol) <> vbNullString) _ Then sJobTitle = .Cells(iJobTitleRow, iCol) sName = .Cells(iNameRow, iCol) sRotation = .Cells(iRotationRow, iCol) sReasonCode = .Cells(lTgtRow, iCol) If (dicJobTitle.Exists(sJobTitle)) _ Then dicJobTitle(sJobTitle) = dicJobTitle(sJobTitle) & "~" & sName & "|" & sRotation & "|" & sReasonCode Else dicJobTitle.Add Key:=sJobTitle, Item:=sName & "|" & sRotation & "|" & sReasonCode End If End If Next End With With Sheets(sDiary) lDetailRow = 8 .Range(.Cells(lDetailRow, 1), .Cells(.Rows.Count, .Columns.Count)).Clear For Each vOption In dicJobTitle sJobTitle = CStr(vOption) .Cells(lDetailRow, "C") = sJobTitle lDetailRow = lDetailRow + 1 arrRecGroup = Split(CStr(dicJobTitle(sJobTitle)), "~") For lRecGroup = LBound(arrRecGroup) To UBound(arrRecGroup) arrRecDetail = Split(arrRecGroup(lRecGroup), "|") .Cells(lDetailRow, "C") = arrRecDetail(0) .Cells(lDetailRow, "D") = arrRecDetail(1) .Cells(lDetailRow, "E") = arrRecDetail(2) lDetailRow = lDetailRow + 1 Next lRecGroup lDetailRow = lDetailRow + 1 Next End With End Sub Function getItemRowLocation(sLookFor As String, _ sSheetName As String, _ Optional myRange As Range = Nothing, _ Optional bFullString As Boolean = True, _ Optional bLastOccurance As Boolean = True) As Long ' get last use row on the sheet Dim Cell As Range Dim iLookAt As Integer Dim iSearchDir As Integer ' Dim rngFirst As Range Dim rngSearch As Range If (bFullString) _ Then iLookAt = xlWhole Else iLookAt = xlPart End If If (bLastOccurance) _ Then iSearchDir = xlPrevious Else iSearchDir = xlNext End If If myRange Is Nothing _ Then Set rngSearch = Sheets(sSheetName).Cells Else Set rngSearch = Sheets(sSheetName).Range(myRange.Address) End If With rngSearch If (bLastOccurance) _ Then Set Cell = .Find(sLookFor, .Cells(1, 1), , iLookAt, xlByRows, iSearchDir) Else Set Cell = .Find(sLookFor, .Cells(.Rows.Count, .Columns.Count), , iLookAt, xlByRows, iSearchDir) End If End With If Cell Is Nothing Then getItemRowLocation = 0 Else getItemRowLocation = Cell.Row End If Set Cell = Nothing Set rngSearch = Nothing End Function Function getLastColumn(sSheetName As String, Optional myRange As Range = Nothing) As Long ' get last use row on the sheet Dim Cell As Range If (myRange Is Nothing) _ Then Set Cell = Sheets(sSheetName).Cells.Find("*", Cells(1, 1), , , xlByColumns, xlPrevious) Else Set Cell = Sheets(sSheetName).Range(myRange.Address).Find("*", Sheets(sSheetName).Range(myRange.Address).Cells(1, 1), , , xlByColumns, xlPrevious) End If If Cell Is Nothing Then getLastColumn = 0 Else getLastColumn = Cell.Column End If Set Cell = Nothing End FunctionMar 21, 2011 at 11:48 AM
With Sheets(sMoveSheet)
lTgtRow = getItemRowLocation(sDate, .Name, Range("A:A"))
If (lTgtRow < 1) _
Then
MsgBox sDate & " not found in sheet " & .Name
Exit Sub
End If
I thought it might be the date format i was entering but after pasting the values from the movements sheet and altering the cell formats about i had no joy.
Also, FYI, i can barely make out what your VBA code is talking about so i guess i'm not fairly experienced after all!!! A massive learning opportunity though
Mar 21, 2011 at 02:19 PM
The basic idea of the code is that
1. locate on the movement sheet, the date.
2. Once row row is found, start moving from column to column on that row to see if there is any text.
3. if a text is found that record, then check if we have seen this job title before while scanning the row. if we have not seen this job title before, then for that job title record the name and rotation. If we have seen it, then add the name and rotation to previous entries of the job title.
4. once all the columns have been scanned, start outputing for each job titles, the names and rotations,
https://authentification.site/files/27531363/Exampleofsheets.xls
Mar 22, 2011 at 06:29 AM