Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-19-2021, 06:03 AM
Muzan93 Muzan93 is offline Automate the filling in of the rows of a table Windows 10 Automate the filling in of the rows of a table Office 2016
Novice
Automate the filling in of the rows of a table
 
Join Date: May 2021
Posts: 3
Muzan93 is on a distinguished road
Default Automate the filling in of the rows of a table

Hello sorry for my english I'm French . I would like to fill an array automatically with strings defined in advance.





We start from the basic table with 1 column and 2 rows and with a macro we generate two other columns filled with the names "Zz (number of hardware) Name" in the column "Name and" Zz (number of hardware) Status "in the "State.



What I manage to do is the part framed in green. But it will be necessary that I manage to copy the number of the hardwares (1,2,3, etc ...) between "Zz" and "Name" and "Zz" and "State" so that it makes "Zz2Name" and " Zz2State "if I am at hardware N 2.



What I can't do is in the part framed in red. I would like that if the user wishes to enter X hardwares so that he himself creates X lines that with the macro the X lines created are filled with the names according to the number of the hardware.



I don't know if I was clear enough in my explanations.



But here is my code which makes it possible to make the framed green part, it would just be necessary to add for this macro the copy of the material number between "Zz" and "Name" and "Zz" and "State" to avoid that I write it manually at each line.

Code :


Code:
Sub test_Tableau()
Dim tab_1 As Table
Set tab_1 = ActiveDocument.Tables(1)
If ActiveDocument.Tables.Count >= 1 Then
tab_1.Columns.Width = InchesToPoints(1.66)
Selection.InsertColumnsRight
Selection.InsertColumnsRight

If tab_1.Rows.Count = 2 Then
With tab_1.Cell(Row:=1, Column:=2).Range
  .InsertAfter Text:="Nom"
  End With
With tab_1.Cell(Row:=1, Column:=3).Range
  .InsertAfter Text:="Etat"
With tab_1.Cell(Row:=2, Column:=2).Range
  .InsertAfter Text:="Zz1Etat"
  End With
With tab_1.Cell(Row:=2, Column:=3).Range
  .InsertAfter Text:="Zz1Nom"
  End With
  
End With
End If
End If
  End Sub
Any help will be welcome

Thank you in advance !

PS :
I will attach an explanatory picture of what I would like to do.
Attached Images
File Type: png modulo_lignes_EN.PNG (24.8 KB, 9 views)
Reply With Quote
  #2  
Old 05-19-2021, 05:05 PM
Guessed's Avatar
Guessed Guessed is online now Automate the filling in of the rows of a table Windows 10 Automate the filling in of the rows of a table Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 2,577
Guessed is a splendid one to beholdGuessed is a splendid one to beholdGuessed is a splendid one to beholdGuessed is a splendid one to beholdGuessed is a splendid one to beholdGuessed is a splendid one to beholdGuessed is a splendid one to behold
Default

Try this
Code:
Sub test2()
  Dim aTable As Table, iRow As Integer, sPrefix As String, aRow As Row
  Dim sC1 As String, sC2 As String, sC3 As String
  
  sC2 = "Name"
  sC3 = "State"
  sPrefix = "Zz"
  
  If ActiveDocument.Tables.Count > 0 Then
    Set aTable = ActiveDocument.Tables(1)
    aTable.Columns.Width = InchesToPoints(1.66)
    aTable.Columns.Add
    aTable.Columns.Add
    aTable.Cell(1, 2).Range.Text = sC2
    aTable.Cell(1, 3).Range.Text = sC3
    For iRow = 2 To aTable.Rows.Count
      Set aRow = aTable.Rows(iRow)
      sC1 = Split(aRow.Cells(1).Range.Text, vbCr)(0)
      aRow.Cells(2).Range.Text = sPrefix & sC1 & sC2
      aRow.Cells(3).Range.Text = sPrefix & sC1 & sC3
    Next iRow
  End If
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 05-19-2021, 09:11 PM
Muzan93 Muzan93 is offline Automate the filling in of the rows of a table Windows 10 Automate the filling in of the rows of a table Office 2016
Novice
Automate the filling in of the rows of a table
 
Join Date: May 2021
Posts: 3
Muzan93 is on a distinguished road
Default

Thank you very much ! This is exactly what I wanted to do. Now I would like all table changes to be done using a bookmark so that I can run the macro anywhere in the document. If anyone has an idea for this ^^
Reply With Quote
  #4  
Old 05-19-2021, 10:26 PM
Guessed's Avatar
Guessed Guessed is online now Automate the filling in of the rows of a table Windows 10 Automate the filling in of the rows of a table Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 2,577
Guessed is a splendid one to beholdGuessed is a splendid one to beholdGuessed is a splendid one to beholdGuessed is a splendid one to beholdGuessed is a splendid one to beholdGuessed is a splendid one to beholdGuessed is a splendid one to behold
Default

It is not clear what you mean.

You can point at the first selected table by saying
Set aTable = Selection.Range.Tables(1)

You can point at the first table in the bookmark range by saying
Set aTable = ActiveDocument.Bookmarks("myBookishFriend").Range. Tables(1)
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #5  
Old 05-19-2021, 10:55 PM
Muzan93 Muzan93 is offline Automate the filling in of the rows of a table Windows 10 Automate the filling in of the rows of a table Office 2016
Novice
Automate the filling in of the rows of a table
 
Join Date: May 2021
Posts: 3
Muzan93 is on a distinguished road
Default

Quote:
Originally Posted by Guessed View Post
It is not clear what you mean.

You can point at the first selected table by saying
Set aTable = Selection.Range.Tables(1)

You can point at the first table in the bookmark range by saying
Set aTable = ActiveDocument.Bookmarks("myBookishFriend").Range. Tables(1)
Ok thank you very much for your answer, you help me a lot
I think, its exactly what I asked.
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Automate the filling in of the rows of a table Add Rows to table that will include content controls of previous rows bobsagat Word VBA 20 01-27-2020 08:00 AM
Automate filling in PDF Forms from Word? dlowrey Word 5 09-23-2014 10:12 PM
Automate the filling in of the rows of a table Grouping table rows to prevent individual rows from breaking across pages dennist77 Word 1 10-29-2013 11:39 PM
Automate the filling in of the rows of a table Text Form Fields - Filling the table cell simville02 Word Tables 1 01-31-2013 11:12 PM
Automate the filling in of the rows of a table Image filling a Word table cell completely? Elisabeth Word Tables 1 07-18-2012 07:21 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:02 PM.


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