Apachefoorumi.net
Sielussani on mursu...
Sub ColumnToTable()
''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' ColumnToTable
' This transforms the column of data with a defined name
' of "ColumnData" to a two dimensional table whose upper
' left cell is named "StartTable". The block size of
' the data in ColumnData is specified by C_BLOCK_SIZE.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim ColumnData As Range ' The original column of data
Dim RNdx As Long ' Row index
Dim CNdx As Long ' Column index
Dim StartRow As Long ' Row number of Range("StartTable")
Dim StartColumn As Long ' Column number of Range("StartTable")
Dim N As Long ' Index into ColumnData
Dim WS As Worksheet ' Worksheet reference
Const C_BLOCK_SIZE = 5 ' Block size of data in ColumnData
'''''''''''''''''''''''''''
' Initialize the variables.
'''''''''''''''''''''''''''
Set ColumnData = Range("ColumnData")
StartRow = Range("StartTable").Row
StartColumn = Range("StartTable").Column
RNdx = StartRow
CNdx = StartColumn
Set WS = Worksheets("UsingVBA")
N = 0
''''''''''''''''''''''''''''''''''''''
' Loop across then down filling
' cells with element N of ColumnData.
''''''''''''''''''''''''''''''''''''''
For RNdx = StartRow To (StartRow + (ColumnData.Rows.Count / C_BLOCK_SIZE))
For CNdx = StartColumn To StartColumn + C_BLOCK_SIZE - 1
N = N + 1
WS.Cells(RNdx, CNdx).Value = ColumnData.Cells(N, 1)
Next CNdx
Next RNdx
End Sub
Page created in 0.059 seconds with 24 queries.