I need to have VBA code to look up the value in Column A and then search for the most recent date in Column B corresponding to this value , and then add the work “ current “ in the adjacent cell for this date and “ superseded” to the old date
very good code and working for the test file
But when I enter new row for the same document no it doesn’t change the status automatically and I have to run the macro again and this take too much time since I have over than 900000 row.
Can you please make this code update faster ?
Martin Liss
When you add a new row, can it be anywhere in the sheet, or is it always at the bottom?
Private Sub Worksheet_Change(ByVal Target As Range)Dim lngLastRow As LongDim lngRow As LongDim lngMax As LongDim rngVisible As RangeDim dteMostRecent As DateDim lngMR_Row As LongApplication.ScreenUpdating = FalseActiveSheet.UsedRange.AutoFilterlngLastRow = Range("A1048576").End(xlUp).RowIf Not Intersect(Target, Range("A2:B" & lngLastRow)) Is Nothing Then If Cells(Target.Row, "A") = Empty Or Cells(Target.Row, "B") = Empty Then Exit Sub Else Range("$A$1:$C$" & lngLastRow).AutoFilter Field:=1, Criteria1:=Cells(Target.Row, "A") Set rngVisible = ActiveSheet.AutoFilter.Range.SpecialCells(xlCellTypeVisible) dteMostRecent = #1/1/1950# Application.EnableEvents = False For lngRow = ActiveSheet.AutoFilter.Range.Offset(1).SpecialCells(xlCellTypeVisible).Cells(1, 2).Row To rngVisible.End(xlDown).Row Cells(lngRow, "C") = "Superseded" If DateDiff("d", dteMostRecent, Cells(lngRow, "B")) > 0 Then dteMostRecent = Cells(lngRow, "B") lngMR_Row = lngRow End If Next Cells(lngMR_Row, "C") = "Current" Application.EnableEvents = True End IfEnd IfActiveSheet.UsedRange.AutoFilterApplication.ScreenUpdating = True
hello, i would insert row anywhere in the log, not necessary at last row.
i copied the second code to my file but its not working , i am not sure what is wrong.. can you please check it again ? thanks a lot.
Martin Liss
When I tested it it worked for me. What I did was to
Right-click on an existing row number and selected Insert
Copied the "Name" from the above row and pasted it into column "A" of the new row
Entered a date into the "Date" column of the new row
Selected any other cell
Did you do something different?
Can you attach your workbook or send it to me in an EE message.
sorry i was not clear , i have no problem to insert row in anywhere in the file, but i couldn't copy the second macro to my file.
i have attached copy of original file. sorry for disturbing you Martin about this but please note that :
Column A : Document Name
Column E: Rev. Status
Column M: Received_Date
start row : 6
very good Martin, and this is what i really wish to have for my file, but please see below 2 points need your help with :
1 - i set up filter in the header row ( row No 6) , and when i search for any document using filter and try to update revision , immediately filter will disappear , can you please fix it ?
2- i have moved all my data to the file ( more than 104385 rows ) and i have to click double click in each cell in the column E " Rev Status " in order to activate the macro and word " current " will appear for the most recent date. is it possible to make this process with other macro to refresh all data after update ?
sorry for late reply , i have sent you reply . kindly check
M. Saad
ASKER
hello , i am very thankful for your great work , only few advise from you if possible, i have sent you reply . kindly check
M. Saad
ASKER
Dear Martin
i am speechless , this exactly what i wanted to have in my file , working like charm. this will save a lot of time and efforts for my daily work, very happy indeed.
really appreciate your great efforts during all week and high ethics ,I am trying it since morning and its really good , everything is very good for me.
sample of final file is attached for further use by anybody looking for the same.
Open in new window