Is it possible to have Excel freeze a calculated date until the calculated date itself has passed?
Within the Excel example below, Today's Date is formulated with TODAY(), and Next Proposed Meeting is a calculated date by adding Today's Date plus Meeting Cadence.
Excel Example:
Here is what I'm looking to do: when a user opens the workbook and sets the initial meeting cadence, I would like to freeze the Next Proposed Meeting date until that specific date meets the date referenced in today's date.
(Example: today's date is Monday, October 1, 2018 and the next proposed meeting date is Monday, October 1, 2018).
When the two dates match, I would like it to cycle to the next date, depending on the numerical value of the cadence. So, if the meeting cadence continued to be 7 days, the Next Proposed Meeting cell would automatically populate to "Monday, October 8, 2018."
What would be the best way to accomplish this?
Cheers, and thank you!
:)
Hacked this out.
In a module:
Sub setCurrentProposedDate(cadenceChanged As Boolean)
Dim currProposedDate As Name, currCadence As Name
Set currProposedDate = ThisWorkbook.Names.Item("CurrentProposed")
Set currCadence = ThisWorkbook.Names.Item("CurrentCadence")
If cadenceChanged Then
currProposedDate.Value = Sheet1.Range("B2").Value - Evaluate(currCadence.Value) + Evaluate(currProposedDate.Value)
currCadence.Value = Sheet1.Range("B2").Value
End If
If Sheet1.Range("B1").Value - Evaluate(currProposedDate.Value) >= 0 Then
currProposedDate.Value = Sheet1.Range("B2").Value + Evaluate(currProposedDate.Value)
End If
End Sub
In workbook module:
Private Sub Workbook_Open()
setCurrentProposedDate False
End Sub
In Sheet1 module:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Sheet1.Range("B2")) Is Nothing Then
setCurrentProposedDate True
End If
End Sub
Set workbook level names to be :
Put this formula in B3:
=CurrentProposed
Here is a stab at doing that via formula...
- Set a Project Start Date such as Monday, 3 September, 2018 in B1
- Enter your cadence value (7, 10, 14, etc.) in B2
- Formula for "Next Meeting" in B3 is =SUM(B1,PRODUCT(ROUNDDOWN(DAYS(TODAY(),B1)/B2,0)+1,B2))
Explanation:
- The Rounded down value of the date difference between two dates (Start Date and Today) gives you a whole number indicating the number of periods (based on cadence) you are after the start
- Add one to that b/c you want to predict the next meeting date
- Multiply that by the cadence to get the number of days until next meeting date (from the start)
- Modify the cadence (B2) and your next meeting date should adjust appropriately.
I tested with my project and a few random dates and cadences and it seems to work.
Related
Recently I needed to set some dates in Excel to the nearest Wednesday for a scheduling process.
I found some answers here in stackoverflow and other sites but none were giving the desired result at all times. So, I wrote a little sub to achieve this for any day you need, but it got me wondering if there was a better way to achieve this, if not then I hope you find it helpful.
EDIT: This sub is part of a large process run by a macro by clicking a custom ribbon button, the input dates come from an array, therefore, I have to use vba to change them.
Here is the matrix with results:
And the code is this:
Sub SetNextWed()
Range("A6").Activate
Do Until ActiveCell.Value = ""
SetToNextDate ActiveCell.Value, vbWednesday, 2
ActiveCell.Offset(1, 0).Activate
Loop
End Sub
Sub SetToNextDate(MyDate As Date, DayOfWeek As Integer, Column As Integer)
Dim dNext_Wednesday As Date
dNext_Wednesday = MyDate
Select Case Weekday(MyDate)
Case DayOfWeek
dNext_Wednesday = MyDate
Case Else
dNext_Wednesday = MyDate + DayOfWeek - Weekday(MyDate)
If MyDate > dNext_Wednesday Then
dNext_Wednesday = MyDate + ((DayOfWeek + 7) - Weekday(MyDate))
End If
End Select
I've tried this solutions:
https://vbaf1.com/date-time/next-wednesday-date/
https://www.mrexcel.com/board/threads/determine-date-of-next-and-most-recent-monday-vba.983467/
How do I find out what the Date is for Next Saturday or the current Saturday?
In Excel, dates are just numbers, and the date number modulo 7 gives you the day of the week, with 0 as Saturday through 6 as Friday. So you don't need VBA. The following cell formula calculates the Wednesday date you desire: =7*INT((A1+2)/7)+4, assuming the original date is in A1.
I have a worksheet with three columns. Column C:C has all calendar dates, N:N contains Data 1 and R:R Data 2.
The macro I am trying to write should check dates in Column C to find dates that are (EDIT) less than today and copy data of Column R:R to Column N:N.
Does this make sense? I have a feeling it's a super basic thing, but oh well, I spent one hour Googling without success.
Example
Thanks!
In Excel a date is just the number of days which starts counting from January 1st 1900. So January 1, 1900 is number 1. With this in mind, it is very easy to calculate with dates. Hours and minutes are fractions.
This sub should do the job:
Sub CopyData()
For i = 1 To 100
If Cells(i, 3) < DateTime.Date Then
Cells(i, 14) = Cells(i, 18)
End If
Next
End Sub
Replace the number 100 with the amount of lines you have or with some logic to count the number of lines.
Succes.
I have an Excel macro which calculates no. of hours spent on a task for each day in a month.
The first row contains day numbers from 1 to 31 and data is filled using the macro accordingly for each day number for a month. The sheet name contains the month name.
Now, the problem is the macro leaves blank for the days for which data is not available. That day can be a Saturday, Sunday, or the person was absent that day.
I want the macro to identify weekends and highlight those with gray color so that only absent days appear as blank.
Using cell formulas and conditional formatting (VBA below)
You could do this quite easily with the built-in WEEKDAY cell formula, together with the DATE formula.
By setting up the year and month value in the sheet, you can create an extra column which gives the day of the week as a number between 1 and 7:
=WEEKDAY(DATE($A$2, $B$2,C2))
Then you can set up conditional formatting to colour days 7 and 1 (Saturday and Sunday respectively) grey
Using VBA
You can apply the same logic as above, but from a sub. This doesn't require the month and year values to be stored in the sheet, and takes the month from the sheet name. It then directly colours the day number grey if on the weekend.
Sub weekdayhighlight()
Dim days As Range
Set days = ActiveSheet.Range("C2:C8") ' Range where date numbers are stored, 1,2,...,31
Dim month As String
month = ActiveSheet.Name ' Active sheet name is "May"
Dim day As Range
Dim daynum As Long
' Loop over days to test for weekday
For Each day In days
' Get day number, from date in format "1 May, 2017"
daynum = Weekday(DateValue(day.Value & " " & month & ", 2017"), firstdayofweek:=vbSunday)
If daynum = 7 Or daynum = 1 Then
day.Interior.Color = RGB(200, 200, 200) ' Grey for saturdays or sundays
End If
Next day
End Sub
Note: This macro will throw an error if you try and compute the weekday of a non-existant date, for instance the 31st of Feb. You say each sheet has day numbers from 1 to 31, you should limit that to actual existing dates or add error handling to the code.
Try combining your sheet name and column headers into date (what about a year?) in a loop and then use DatePart() function to determine whether it is weekend day or not. It would be easier if column headers were real dates (may be formatted to show day only).
I have spreadsheet with mutliple rows in which a few are dates. The problem is that while some rows are in english date format, few others are in spanish format eg. Octubre 1, 2015, Septiembre 1, 2014 etc. What could be the easiest way to convert all of them into english format dates.
Give this small macro a try:
Sub Converter()
ary = Split("Enero, January, Febrero, February, Marzo, March, Abril, April, Mayo, May, Junio, June, Julio, July, Agosto, August, Septiembre, September, Octubre, October, Noviembre, November, Diciembre, December", ", ")
For I = 0 To 23 Step 2
Cells.Replace What:=ary(I), Replacement:=ary(I + 1)
Next I
End Sub
The following sub will select all cells containing dates (irrespective of how they are formatted) on the active sheet. If you run it and then right-click on one of the selected cells and select format cells from the drop-down menu, you can decide on a common date format:
Sub SelectDates()
Dim dates As Range
Dim cell As Range
For Each cell In ActiveSheet.UsedRange
If IsDate(cell.Value) Then
If dates Is Nothing Then
Set dates = cell
Else
Set dates = Union(dates, cell)
End If
End If
Next cell
dates.Select
End Sub
I am trying to move data from a 5 column spread sheet in excel to other sub spread sheets based on one of the date columns in the first spread sheet. The sub-spreadsheets will be created if they do not exist, otherwise they will be populated with data from the master spreadsheet. The spread sheets names will be a date that is the start of the week(being monday). my columns are: Work Order, Description, Location, Asset, Date.
Example:
Work Order - Description - Location - Asset - Date
123 ---------- test&inspect - NC-231 - KK32 - 8/21/14
In this example my master spreadsheet with a date row of 8/21/14 will create a subspread sheet with a name of 8/18/14 since this row falls in the week of 8/18/14 and insert the other columns with it. How can this be done inside of an excel workbook?
Dim firstDate As Date, secondDate As Date
Dim I as Date
firstDate = Inputbox("What start date?") ' request your input for what date Monday is
secondDate = DateAdd("d", 6, firstDate)
For Each Cell in Range("E2"),Range("E2").End(xldown)
ActiveCell = Cell
If cell => firstdate and =< secondate then ' test if falls under days of week
ActiveCell.Row.Copy
On error resume next
Worksheets.Add.Name = Firstdate
Sheets(" & Firstdate &").Select
Range("A1").End(lxDown).Offset(1,0).pastespecial
Next Cell
End Sub
Not tested but should be a start .