-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathConvertListToTable.vbs
37 lines (28 loc) · 1.03 KB
/
ConvertListToTable.vbs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
'CREDIT
'https://exceloffthegrid.com/copy-a-data-table-from-pdf-into-excel/
Sub ConvertListToTable()
'Define the variables
Dim NoOfColumns As Integer
Dim TargetRow As Integer
Dim TargetCol As Integer
Dim i As Integer
'Set the initial values for the variables of where to place the table
TargetRow = Selection.Row
TargetCol = Selection.Column
'Set the variable of the number of columns in the table
'NoOfColumns = 5
'Get input from the user
NoOfColumns = InputBox("How many columns should the table have?")
'loop through every cell in the selected range
For i = 0 To Selection.Rows.Count - 1
'Change the value for the Target Column
TargetCol = TargetCol + 1
'Set the value of the Target Cell based our the Source Cell
Cells(TargetRow, TargetCol).Value = Cells(Selection.Row + i, Selection.Column).Value
'Reset the Target Column and change the value for the Target Row
If TargetCol = Selection.Column + NoOfColumns Then
TargetRow = TargetRow + 1
TargetCol = Selection.Column
End If
Next i
End Sub