Hi there
What I want is for the date format to be changed from dd/mm/yy 00:00:00 to dd/mm/yy which I can do with formula
but I'm not sure how to do this in code form column HCode:=INT(H6)
I then need to take the new date format and if that is greater than or equal to 20/01/2010 then run the formula
All in a macro.Code:=H1+67 - Weekday(H1+61)
I was trying advanced filter but I am not sure how to do this.
This code works for the full column but does not only run weekday formula for anything after 20/01/2010 plus is in wrong date format so cannot do analysis on it after.
All help gratefull recieved.Code:Private Sub DetermineDocsDeadline(m, Rtn) If ws1.Cells(m, "H") >= "19/01/2010 00:00:00" Then Rtn = ws1.Cells(m, "H") + 67 - Application.WorksheetFunction.Weekday(ws1.Cells(m, "H") + 61) End If End Sub
Libby
Hello Libby,
It looks like you need a User Defined Function or UDF for short. A UDF can be used on a Worksheet like a formula. If I understand what you want to do correctly then this UDF should do it. If not, let me know and we'll work on it. The result is returned to the cell that called the UDF.
UDF ExampleCode:Function DetermineDocsDeadline(m As Range) As Variant Dim D As Long If IsDate(m) = True Then D = CLng(m) If D >= CLng(CDate("19/01/2010")) Then DetermineDocsDeadline = CDate((D + 67) - (Weekday(D) + 61)) End If End If End Function
Code:'Place this code in a cell =DetermineDocsDeadline(H1)
Sincerely,
Leith Ross
Remember To Do the Following....
1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.2. Thank those who have helped you by clicking the Starbelow the post.
3. Please mark your post [SOLVED] if it has been answered satisfactorily.
Old Scottish Proverb...
Luathaid gu deanamh maille! (Rushing causes delays!)
Hi Leith,
Thanks for this. I was trying to avoid putting any formula in the sheet as the sheet has around 30 thousand rows and it adds to the memory.
Plus it won't let me put
in it says name not valid.Code:=DetermineDocsDeadline(H1)
Is there any way we can put it in the code without having any formula in the sheet. If not what do I need to do to allow this to work.
Thank you and apologies for the delay in getting back to you.
Libby
Hello Libby,
I have rewritten the macro. You can either run this using ALT+F8 (Macro Dialog) or by attaching it to a button on the sheet. It assumes the data is on the "Sheet1". It compares the values in column "H" against the deadline in the macro. Once all the dates have been checked, the new dates are copied over to "Sheet2" starting in cell "A1".
Code:'Written: March 18, 2010 'Author: Leith Ross Sub DetermineDeadlines() Dim D As Long Dim Deadline As Long Dim DocDates() As Variant Dim DstWks As Worksheet Dim Rng As Range Dim RngEnd As Range Dim SrcWks As Worksheet Deadline = CLng(CDate("19/01/2010")) Set SrcWks = Worksheets("Sheet1") Set DstWks = Worksheets("Sheet2") Set Rng = SrcWks.Range("H1") Set RngEnd = SrcWks.Cells(Rows.Count, Rng.Column).End(xlUp) Set Rng = IIf(RngEnd.Row < Rng.Row, Rng, SrcWks.Range(Rng, RngEnd)) ReDim DocDates(1 To Rng.Rows.Count, 1 To 1) DocDates = Rng.Value For Each Item In DocDates If IsDate(Item) = True Then D = CLng(Item) If D >= Deadline Then Item = CDate((D + 67) - (Weekday(D) + 61)) End If End If Next Item DstWks.Cells.ClearContents Set Rng = DstWks.Range("A1").Resize(UBound(DocDates), 1) Rng.Value = DocDates() End Sub
Sincerely,
Leith Ross
Remember To Do the Following....
1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.2. Thank those who have helped you by clicking the Starbelow the post.
3. Please mark your post [SOLVED] if it has been answered satisfactorily.
Old Scottish Proverb...
Luathaid gu deanamh maille! (Rushing causes delays!)
Hi there,
Thank you for this. Unfortunately this coopies and pastes everything from 20/01/2010 into A1 of Sheet 2 but that is it. It is not removing the time facttor or adding my formula.
I suspect it is something I have done. I would like it to return the item in column I if poss too.
I'm not sure if it is me but I suspect it is.
Thank you
Libby
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks