Share via

Conditional rules in Word table

Anonymous
2024-06-12T19:02:50+00:00

I have a table in a Word document, shown below. I want to create a condition where whatever month is inputted in the first cell on the Month row, that the following cells in the row will auto-populate sequentially.

For example, if the the first cell is April then the next cells will say May, June, July, etc.

Month: April May June July August September October
Allow:
Actual:
Impact:
+ Days:

I know I can use the Developer tab to add a field and insert an IF condition. But I am not sure the structure of the rule to ensure it works.

Microsoft 365 and Office | Word | Other | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

2 answers

Sort by: Most helpful
  1. Anonymous
    2024-06-13T11:28:36+00:00

    You could do this with the OnExit event of a content control inserted in the second column of the "Month" row. Let's tag it "StartMonth"

    Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
    Dim oRow As Row
    Dim strDate As String
    Dim lngIndex As Long
    Dim lngCol As Long
    Select Case ContentControl.Tag
    Case "StartMonth"
    Set oRow = ContentControl.Range.Rows(1)
    strDate = "1 " & Left(oRow.Cells(2).Range.Text, Len(oRow.Cells(2).Range.Text) - 1) & ", 2024"
    If IsDate(strDate) Then
    lngIndex = 1
    For lngCol = 3 To oRow.Cells.Count
    oRow.Cells(lngCol).Range.Text = Format(DateAdd("M", lngIndex, CDate(strDate)), "MMMM")
    lngIndex = lngIndex + 1
    Next lngCol
    End If
    End Select
    lbl_Exit:
    Exit Sub
    End Sub

    I am not a fan of all the AI idiots out there spewing half baked VBA solutions. It would be interesting to see the CoPilot's response to your question though.

    P.S., You could make the StartMonth content control a dropdown list containing the 12 months already spelled out.

    Was this answer helpful?

    2 people found this answer helpful.
    0 comments No comments
  2. Suzanne S Barnhill 278.1K Reputation points MVP Volunteer Moderator
    2024-06-13T00:52:37+00:00

    This is a task better suited for Excel, which can autocomplete the cells automatically.

    Was this answer helpful?

    2 people found this answer helpful.
    0 comments No comments