ragav_in
07-12-2023, 06:35 AM
All,
This is my first post, and before posting, I checked the forum, but was not able to find what I was looking for. I am new to VBA. I have a Table in MS Word Document which contains 4 Columns and n Rows (dynamic). The 4th Column is for Review Date and will have various Dates and Format as shown below.
S. No
Version
Description
Review Date
1
1.0
Description A
25/12/2019
2
1.1
Description B
9-JUN-2022
3
1.2
Description C
9-NOV-2022
4
2.0
Description D
6-JUL-2023
5
3.0
Description E
7-Jan-2023
6
3.8
Description F
7-Jul-2023
I have lots of word documents in a specific folder. The task in hand is to scan through each document, and find the table that contains the Review Date; normally identified by ActiveDocument.Tables(3). The code has to go through each value in that Column and check if the date value matches the format of "d-Mmm-YYYY".
Upon checking the table, if the code finds a date value in Column 4 which does not match the above format, it should count the number of instances that does not match and write the count to a new word document along with the document name. In the above scenario, it should return the count as 4 as only 7-Jan-2023 & 7-Jul-2023 match the date format of "d-Mmm-YYYY"; the other values are in different format "d-MMM-YYYY" and "dd/mm/yyyy".
The code that I have is as below, which provides a message box if the format matches. I need the below code to be tweaked to count the total number of format mismatch and provide the count as output of the macro. Your time and help is deeply appreciated.
Sub check_reviewDateFormat()
Dim aTable As Table, fdate, sdate, tdate, strCellText As String
Dim r As Long, c As Long
Set aTable = ActiveDocument.Tables(3)
With aTable
For r = 2 To .Rows.Count
For c = 4 To .Columns.Count
If .Cell(r, 4).Range.Text <> "" Then
fdate = .Cell(r, 4).Range.Text
End If
sdate = Trim(Left(fdate, Len(fdate) - 2))
tdate = Format(sdate, "d-MMM-YYYY")
MsgBox tdate
If sdate = tdate Then
MsgBox "Correct Format"
Else: MsgBox "InCorrect Format"
End If
Next
Next
End With
End Sub
Any help in this regard is deeply appreciated and thanks in advance for all those who put your time to go through this post.
Thanks
ragav_in
This is my first post, and before posting, I checked the forum, but was not able to find what I was looking for. I am new to VBA. I have a Table in MS Word Document which contains 4 Columns and n Rows (dynamic). The 4th Column is for Review Date and will have various Dates and Format as shown below.
S. No
Version
Description
Review Date
1
1.0
Description A
25/12/2019
2
1.1
Description B
9-JUN-2022
3
1.2
Description C
9-NOV-2022
4
2.0
Description D
6-JUL-2023
5
3.0
Description E
7-Jan-2023
6
3.8
Description F
7-Jul-2023
I have lots of word documents in a specific folder. The task in hand is to scan through each document, and find the table that contains the Review Date; normally identified by ActiveDocument.Tables(3). The code has to go through each value in that Column and check if the date value matches the format of "d-Mmm-YYYY".
Upon checking the table, if the code finds a date value in Column 4 which does not match the above format, it should count the number of instances that does not match and write the count to a new word document along with the document name. In the above scenario, it should return the count as 4 as only 7-Jan-2023 & 7-Jul-2023 match the date format of "d-Mmm-YYYY"; the other values are in different format "d-MMM-YYYY" and "dd/mm/yyyy".
The code that I have is as below, which provides a message box if the format matches. I need the below code to be tweaked to count the total number of format mismatch and provide the count as output of the macro. Your time and help is deeply appreciated.
Sub check_reviewDateFormat()
Dim aTable As Table, fdate, sdate, tdate, strCellText As String
Dim r As Long, c As Long
Set aTable = ActiveDocument.Tables(3)
With aTable
For r = 2 To .Rows.Count
For c = 4 To .Columns.Count
If .Cell(r, 4).Range.Text <> "" Then
fdate = .Cell(r, 4).Range.Text
End If
sdate = Trim(Left(fdate, Len(fdate) - 2))
tdate = Format(sdate, "d-MMM-YYYY")
MsgBox tdate
If sdate = tdate Then
MsgBox "Correct Format"
Else: MsgBox "InCorrect Format"
End If
Next
Next
End With
End Sub
Any help in this regard is deeply appreciated and thanks in advance for all those who put your time to go through this post.
Thanks
ragav_in