Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 12-21-2021, 11:13 PM
azhr azhr is offline Add the value of a cell in the table to another cell Windows 10 Add the value of a cell in the table to another cell Office 2010
Novice
Add the value of a cell in the table to another cell
 
Join Date: May 2019
Posts: 4
azhr is on a distinguished road
Default Add the value of a cell in the table to another cell


I have a word file with a table as attached What is required is an equation that gives me the result of two cells (the Hijri date and the end date) as soon as I write the date of the letter, since the date is not automatically inserted and in the same format attached
Attached Files
File Type: docx Question2.docx (13.6 KB, 8 views)
Reply With Quote
  #2  
Old 12-22-2021, 01:37 AM
gmayor's Avatar
gmayor gmayor is offline Add the value of a cell in the table to another cell Windows 10 Add the value of a cell in the table to another cell Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,137
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Because of the Hijri date calculation, this is a task best performed using a macro and content controls. Save the attached as a macro enabled template and create a new document from it. The three content controls will be filled with the appropriate dates for the date the document is created. Note that your example appears to have the Hijri Date one day adrift according to the various on-line calculators, however this is not an area I am familiar with.
They code in the attached is as follows:
Code:
Option Explicit
'Graham Mayor - https://www.gmayor.com - Last updated - 22 Dec 2021 
Sub AutoNew()
    AddDates
End Sub

Sub AddDates()
Dim oCC As ContentControl
    For Each oCC In ActiveDocument.ContentControls
        Select Case LCase(oCC.Title)
            Case Is = "date"
                oCC.Range.Text = Date
            Case Is = "hijri date"
                oCC.Range.Text = dateHijri(Date)
            Case Is = "end date"
                oCC.Range.Text = Format((Date + 3), "yyyy/mm/dd")
            Case Else
        End Select
    Next oCC
End Sub

Private Function dateHijri(sDate As String) As String
Dim vVal As Variant
Dim dtHijri As Date
    VBA.Calendar = vbCalGreg
    If sDate <> vbNullString Then
        On Error GoTo lbl_Exit
        dtHijri = DateValue(sDate)
        VBA.Calendar = vbCalHijri
        dateHijri = dtHijri
    End If
    VBA.Calendar = vbCalGreg
    Exit Function
lbl_Exit:
    dateHijri = vbNullString
    VBA.Calendar = vbCalGreg
End Function
Attached Files
File Type: docm Question2.docm (32.4 KB, 6 views)
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 12-22-2021, 04:05 AM
azhr azhr is offline Add the value of a cell in the table to another cell Windows 10 Add the value of a cell in the table to another cell Office 2010
Novice
Add the value of a cell in the table to another cell
 
Join Date: May 2019
Posts: 4
azhr is on a distinguished road
Default

thank you

I would like the response to be no macro if possible Regarding the Hijri date, the problem can be solved later I ask how to add 3 days to the date of the letter
Reply With Quote
  #4  
Old 12-22-2021, 04:55 AM
gmayor's Avatar
gmayor gmayor is offline Add the value of a cell in the table to another cell Windows 10 Add the value of a cell in the table to another cell Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,137
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

See https://www.gmayor.com/Zips/DateCalc.zip for information on using fields to add 3 days to a date. I don't know how to convert the Hijri date without using a macro.
The macro solution is simpler.
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #5  
Old 12-22-2021, 09:42 PM
azhr azhr is offline Add the value of a cell in the table to another cell Windows 10 Add the value of a cell in the table to another cell Office 2010
Novice
Add the value of a cell in the table to another cell
 
Join Date: May 2019
Posts: 4
azhr is on a distinguished road
Default

With apologies, I will explain what is required in a simpler way, see the attached file

cell D3 = value of cell D1+3


Cell D2 = the value of cell D1, but the date format changes to Hijri
Attached Files
File Type: docx Question3.docx (39.2 KB, 7 views)
Reply With Quote
  #6  
Old 12-22-2021, 11:06 PM
gmayor's Avatar
gmayor gmayor is offline Add the value of a cell in the table to another cell Windows 10 Add the value of a cell in the table to another cell Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,137
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Your explanation was simple enough before, but what you require is not as simple as you imagine. For example, if you refer to the document I linked the field construction required to add 3 days to the current date is

{QUOTE
{SET Delay 3}
{SET a{=INT((14-{DATE \@ M})/12)}}
{SET b{={DATE \@ yyyy}+4800-a}}
{SET c{={DATE \@ M}+12*a-3}}
{SET d{DATE \@ d}}
{SET jd{=d+INT((153*c+2)/5)+365*b+INT(b/4)-INT(b/100)+INT(b/400)-32045+Delay}}
{SET e{=INT((4*(jd+32044)+3)/146097)}}
{SET f{=jd+32044-INT(146097*e/4)}}
{SET g{=INT((4*f+3)/1461)}}
{SET h{=f-INT(1461*g/4)}}
{SET i{=INT((5*h+2)/153)}}
{SET dd{=h-INT((153*i+2)/5)+1}}
{SET mm{=i+3-12*INT(i/10)}}
{SET yy{=100*e+g-4800+INT(i/10)}}
"{mm}-{dd}-{yy}" \@ "MM/dd/yyyy"}


You cannot simply add 3 to the date or (say) 30th December + 3 would be 32nd December.
You can insert date fields that will give the required values for today's date for the three dates (see attached), but it will not work with typed text dates. You cannot calculate text dates in this manner in a Word table.
If you are not using date fields, the macro approach is still the most sensible option here.






Attached Files
File Type: docx Question3.docx (40.3 KB, 7 views)
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Add the value of a cell in the table to another cell Wish to delete letters to the right of the cursor in a Table cell, but whole cell is being deleted vjvj123 Word VBA 12 09-27-2018 03:09 PM
Add the value of a cell in the table to another cell Clear all cell colors within a range starting at cell A8 and change row of active cell to yellow FUGMAN Excel Programming 7 02-05-2017 08:37 AM
Pasting text from Excel cell into word without creating a table, and keeping the in-cell formatting hanvyj Excel Programming 0 08-28-2015 01:15 AM
Add the value of a cell in the table to another cell Table with text that flows from cell to cell hwrigley Word Tables 7 02-18-2014 02:59 AM
Auto-populate an MS Word table cell with text from a diff cell? dreamrthts Word Tables 0 03-20-2009 01:49 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:26 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft