rakesh seebaruth
Active Member
- Joined
- Oct 6, 2011
- Messages
- 303
Hi Guys
I have in cells A1 19,200, B1 13/05/2020 and cells C1 72. When i execute the VBA a table is created in Word as per below and it continues to 72
Please note that C1 is the number of months(i,e Instal No).
What i want to achieve is to send the other half to the right of the blank of the table.Let me clarify if C1= 72 months then split it half that is send 36 months to the other side of the table.My number of months are even numbers(24,36,48,60,98)
You will notice that i have added 1 to "lngRows = Range("C1").Value + 1" because of the headings
My vba codes are as follows :-
Thanks your help
Regards
rakesh
I have in cells A1 19,200, B1 13/05/2020 and cells C1 72. When i execute the VBA a table is created in Word as per below and it continues to 72
Instal No | Amt(Rs) | Due Date | Instal No | Amt(Rs) | Due Date |
1 | 19200 | 13/05/2020 | |||
2 | 19200 | 13/06/2020 | |||
3 | 19200 | 13/07/2020 | |||
4 | 19200 | 13/08/2020 | |||
5 | 19200 | 13/09/2020 | |||
6 | 19200 | 13/10/2020 | |||
7 | 19200 | 13/11/2020 | |||
8 | 19200 | 13/12/2020 | |||
9 | 19200 | 13/01/2021 | |||
10 | 19200 | 13/02/2021 | |||
11 | 19200 | 13/03/2021 | |||
12 | 19200 | 13/04/2021 | |||
13 | 19200 | 13/05/2021 | |||
14 | 19200 | 13/06/2021 | |||
15 | 19200 | 13/07/2021 | |||
16 | 19200 | 13/08/2021 | |||
17 | 19200 | 13/09/2021 | |||
18 | 19200 | 13/10/2021 | |||
19 | 19200 | 13/11/2021 | |||
20 | 19200 | 13/12/2021 |
Please note that C1 is the number of months(i,e Instal No).
What i want to achieve is to send the other half to the right of the blank of the table.Let me clarify if C1= 72 months then split it half that is send 36 months to the other side of the table.My number of months are even numbers(24,36,48,60,98)
You will notice that i have added 1 to "lngRows = Range("C1").Value + 1" because of the headings
My vba codes are as follows :-
VBA Code:
Sub CreateTableInWord()
Dim objWord As Object
Dim objDoc As Object
Dim objTbl As Object
Dim objRow As Object
Dim objCol As Object
Dim lngCols As Long
Dim lngRows As Long
Dim I As Long
lngCols = 6
lngRows = Range("C1").Value + 1
Set objWord = CreateObject("Word.Application")
objWord.Visible = True
Set objDoc = objWord.Documents.Add(DocumentType:=0)
Set objTbl = objDoc.Tables.Add(Range:=objDoc.Paragraphs(1).Range, NumRows:=lngRows, NumColumns:=lngCols)
Set objRow = objTbl.Rows(1)
objTbl.Cell(1, 1).Range.Text = "Instal No"
objTbl.Cell(1, 1).Range.Bold = True
objTbl.Cell(1, 2).Range.Text = "Amt(Rs)"
objTbl.Cell(1, 2).Range.Bold = True
objTbl.Cell(1, 3).Range.Text = "Due Date"
objTbl.Cell(2, 3) = Range("B1").Value
objTbl.Cell(1, 3).Range.Bold = True
objTbl.Cell(1, 4).Range.Text = "Instal No"
objTbl.Cell(1, 4).Range.Bold = True
objTbl.Cell(1, 5).Range.Text = "Amt(Rs)"
objTbl.Cell(1, 5).Range.Bold = True
objTbl.Cell(1, 6).Range.Text = "Due Date"
objTbl.Cell(1, 6).Range.Bold = True
objTbl.Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
For I = 2 To lngRows
' For j = 1 To intNoOfColumns
objTbl.Cell(I, 1).Range = I - 1
Next
For S = 2 To lngRows
objTbl.Cell(S, 2) = Range("A1").Value
Next
For T = 3 To lngRows
objTbl.Cell(T, 3).Range.Text = Format(DateAdd("m", T - 2, Range("B1").Value), "dd/mm/yyyy")
Next T
Set objCol = Nothing
Set objRow = Nothing
Set objDoc = Nothing
Set objWord = Nothing
End Sub
Thanks your help
Regards
rakesh