Change data from a row to a column

%3CLINGO-SUB%20id%3D%22lingo-sub-1869451%22%20slang%3D%22en-US%22%3EChange%20data%20from%20a%20row%20to%20a%20column%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1869451%22%20slang%3D%22en-US%22%3E%3CP%3EI%20have%20a%20column%20in%20access%20and%2For%20excel%20as%20follows%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EROW%20PCFN%3C%2FP%3E%3CP%3E1.%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20123456%2C%20456789%2C%20452123%2C%20741852%20or%20can%20remove%20commas%20between%20each%20number.%3C%2FP%3E%3CP%3E2.%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20987456%2C%20521364%2C%20796321%2C%20etc.%3C%2FP%3E%3CP%3EI%20am%20trying%20to%20convert%20this%20column%20to%3A%3C%2FP%3E%3CP%3EROW%20PCFN%3C%2FP%3E%3CP%3E1.%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B123456%3C%2FP%3E%3CP%3E2.%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20456789%3C%2FP%3E%3CP%3E3.%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B452123%3C%2FP%3E%3CP%3E4.%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B741852%3C%2FP%3E%3CP%3E5.%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B987456%3C%2FP%3E%3CP%3E6.%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B521364%3C%2FP%3E%3CP%3E7.%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3BETC.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECan%20anyone%20help.%20I%20originally%20received%20this%20data%20in%20a%20excel%20worksheet%20with%20commas%20between%20each%20number.%20I%20can%20take%20out%20the%20commas%20if%20needed.%20I%20have%20also%20copied%20and%20pasted%20the%20column%20in%20a%20table%20in%20access.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20Tom%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1869451%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAccess%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1869794%22%20slang%3D%22en-US%22%3ERe%3A%20Change%20data%20from%20a%20row%20to%20a%20column%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1869794%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F863291%22%20target%3D%22_blank%22%3E%40ygoshy%3C%2FA%3E%26nbsp%3B%3CBR%20%2F%3EI%20will%20try%20to%20come%20up%20with%20a%20sample%20function%20to%20do%20this%2C%20but%20the%20approach%20is%20going%20to%20be%20based%20on%20the%20Split()%20function%20to%20place%20each%20of%20the%20values%20in%20a%20row%20into%20an%20array.%20Take%20a%20few%20minutes%2C%20please%2C%20to%20read%20about%20the%20Split()%20function.%20I'll%20see%20how%20quickly%20I%20can%20do%20it%2C%20but%20it%20may%20be%20a%20little%20while.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Visitor

I have a column in access and/or excel as follows:

 

ROW PCFN

1.      123456, 456789, 452123, 741852 or can remove commas between each number.

2.      987456, 521364, 796321, etc.

I am trying to convert this column to:

ROW PCFN

1.       123456

2.        456789

3.       452123

4.       741852

5.       987456

6.       521364

7.       ETC.

 

Can anyone help. I originally received this data in a excel worksheet with commas between each number. I can take out the commas if needed. I have also copied and pasted the column in a table in access.

 

Thanks Tom

 

3 Replies

@ygoshy 
I will try to come up with a sample function to do this, but the approach is going to be based on the Split() function to place each of the values in a row into an array. Take a few minutes, please, to read about the Split() function. I'll see how quickly I can do it, but it may be a little while.

@George Hepworth

I created two tables, one for the source data and one for the output data. They are identical with two fields: Row and PCFN.

 

This function splits the comma delimited source rows into an array then then extracts the items from the array into the output table, one row per item.

 

 

Public Sub RowToColumn()

On Error GoTo errHandler
Dim rst As DAO.Recordset
Dim db As DAO.Database
Dim arySourceRow() As String
Dim lngRow As Long
Dim i As Integer

lngRow = 1
Set db = CurrentDb
Set rst = db.OpenRecordset(Name:="SELECT Row, PCFN FROM SampleTable", Type:=dbOpenDynaset)
With rst
Do Until .EOF
arySourceRow = Split(!PCFN, ",")
For i = 0 To UBound(arySourceRow())
db.Execute "INSERT INTO FinalData (Row, PCFN) SELECT " & lngRow & ", " & arySourceRow(i), dbFailOnError
lngRow = lngRow + 1
Next i
.MoveNext
Loop
End With


Cleanup:

On Error Resume Next
Set db = Nothing
Set rst = Nothing

exitProc:

Exit Sub

errHandler:

MsgBox Prompt:="Error " & Err.Number & " (" & Err.Description & ") in procedure RowToColumn, line " & Erl & ".", _
Buttons:=vbCritical + vbOKOnly, _
Title:="Something Bad Happened"
Resume Cleanup
Resume

End Sub

 

 

@ygoshy I created a sample relational database application to illustrate this approach. It's on my public OneDrive.