msisepleld
New Member
- Joined
- Aug 5, 2013
- Messages
- 4
Hello everyone!
I am new to VBA macro coding and could use a little assistance.
Issue: My current file has all data in one column "A". How do you transpose X number of sequential rows into their own separate columns?
Possible Solution for what I want: A VBA macro that solves the issue.
My Layman's Explanation:
** My data came in one large column ("A") and this consists of the "Name", "Abbreviation of Name", "Phone Number".
Example: My current data looks like this.
[TABLE="class: grid, align: left"]
<tbody>[TR]
[TD][/TD]
[TD="align: center"]A[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]John Smith[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]JS[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD](202) 456-1111[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]Tom Cruse[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]TC[/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD](213) 580-7500[/TD]
[/TR]
[TR]
[TD]7[/TD]
[TD]Danny Ocean[/TD]
[/TR]
[TR]
[TD]8[/TD]
[TD]DO[/TD]
[/TR]
[TR]
[TD]9[/TD]
[TD](702) 693-7111[/TD]
[/TR]
</tbody>[/TABLE]
** I would like to transpose the data as such.
Example:
[TABLE="class: grid"]
<tbody>[TR]
[TD][/TD]
[TD="align: center"]A[/TD]
[TD="align: center"]B[/TD]
[TD="align: center"]C[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]John Smith[/TD]
[TD]JS[/TD]
[TD](202) 456-1111[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]Tom Cruse[/TD]
[TD]TC[/TD]
[TD](213) 580-7500[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]Danny Ocean[/TD]
[TD]DO[/TD]
[TD](702) 693-7111[/TD]
[/TR]
</tbody>[/TABLE]
Breakdown on how I think the macro would work:
1.) Start on cell "A1" using Explicit Range Formula.
2.) Move to Implicit Next Cell. Ex: "A2"
3.) Copy Cell to Transposed Position. Ex: "B1"
4.) Delete Implicit Row below Starting Row. Ex: Row "2"
5.) Copy new datum in Cell after deletion of Row. Ex: "A2"
6.) Paste Cell to transposed position + 1 column. Ex: "C1"
7.) Delete Implicit Row. Ex: Row "2"
8.) Repeat from "Step 2" with new Implicit Cell. Ex: "A3"
9.) Stop when Explicit Range is completed. Ex: "A1:A1000"
So I believe this would use a combination of a VBA Deletion and VBA Transpose code such as the codes I posted below.
Deletion Code Example:
Transpose Code Example:
Thank you all for your assistance!
I hope this post uses good keywords to help people who look for this solution in the future.
James E.
I am new to VBA macro coding and could use a little assistance.
Issue: My current file has all data in one column "A". How do you transpose X number of sequential rows into their own separate columns?
Possible Solution for what I want: A VBA macro that solves the issue.
My Layman's Explanation:
** My data came in one large column ("A") and this consists of the "Name", "Abbreviation of Name", "Phone Number".
Example: My current data looks like this.
[TABLE="class: grid, align: left"]
<tbody>[TR]
[TD][/TD]
[TD="align: center"]A[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]John Smith[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]JS[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD](202) 456-1111[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]Tom Cruse[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]TC[/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD](213) 580-7500[/TD]
[/TR]
[TR]
[TD]7[/TD]
[TD]Danny Ocean[/TD]
[/TR]
[TR]
[TD]8[/TD]
[TD]DO[/TD]
[/TR]
[TR]
[TD]9[/TD]
[TD](702) 693-7111[/TD]
[/TR]
</tbody>[/TABLE]
** I would like to transpose the data as such.
Example:
[TABLE="class: grid"]
<tbody>[TR]
[TD][/TD]
[TD="align: center"]A[/TD]
[TD="align: center"]B[/TD]
[TD="align: center"]C[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]John Smith[/TD]
[TD]JS[/TD]
[TD](202) 456-1111[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]Tom Cruse[/TD]
[TD]TC[/TD]
[TD](213) 580-7500[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]Danny Ocean[/TD]
[TD]DO[/TD]
[TD](702) 693-7111[/TD]
[/TR]
</tbody>[/TABLE]
Breakdown on how I think the macro would work:
1.) Start on cell "A1" using Explicit Range Formula.
2.) Move to Implicit Next Cell. Ex: "A2"
3.) Copy Cell to Transposed Position. Ex: "B1"
4.) Delete Implicit Row below Starting Row. Ex: Row "2"
5.) Copy new datum in Cell after deletion of Row. Ex: "A2"
6.) Paste Cell to transposed position + 1 column. Ex: "C1"
7.) Delete Implicit Row. Ex: Row "2"
8.) Repeat from "Step 2" with new Implicit Cell. Ex: "A3"
9.) Stop when Explicit Range is completed. Ex: "A1:A1000"
So I believe this would use a combination of a VBA Deletion and VBA Transpose code such as the codes I posted below.
Deletion Code Example:
Code:
Sub Delete_Rows()
Dim rng As Range, cell As Range, del As Range
Set rng = Intersect(Range("A1:C20"), ActiveSheet.UsedRange)
For Each cell In rng
If (cell.Value) = "XXXXXXXX" _
Then
If del Is Nothing Then
Set del = cell
Else: Set del = Union(del, cell)
End If
End If
Next cell
On Error Resume Next
del.EntireRow.Delete
End Sub
Transpose Code Example:
Code:
ActiveChart.PlotBy = xlColumns
ActiveChart.PlotBy = xlRows
'(I AM NOT USEING A CHART SO IT WONT BE THIS.)
Thank you all for your assistance!
I hope this post uses good keywords to help people who look for this solution in the future.
James E.