Hello, I am new to VB and I’m trying to use a macro to sort out my Excel text data. Here is an example of my problem.
ColA Col B
P x1
P x2
P x3
B y1
B y2
C z1
C z2
C z3
I am trying to create a macro to delete repetitions in Column A (Col A) but at the same time put data from Column B (x1, x2 and x3) into different columns under the same Row 1. I’m trying to get my data to look like:
Col A Col B Col C Col D
P x1 x2 x3
B y1 y2
C z1 z2 z3
Due to the large amount of data, I am unable to manually do this and would hence like to automate the process. I came up with some code, but there are errors in it. I would really be grateful if I could get some help on this.
Sub LoopRange()
x = ActiveCell.Row
y = x + 1
Do While Cells(x, 1).Value <> ""
Do While Cells(y, 1).Value <> ""
If (Cells(x, 1).Value = Cells(y, 1).Value) Then Range("B1").Offset(0, 1).Select And Cells(y, 1).EntireRow.Delete
Else
y = y + 1
End If
Loop
x = x + 1
y = y + 1
Loop
End Sub
There is a good chance that this code is nothing but lines of garbage. I really hope someone can help me structure it to meet the requirements of the format mentioned above.
Thank you.
Last edited by beginner123; 09-24-2009 at 04:48 PM.
Your post does not comply with Rule 1 of our Forum RULES. Your post title should accurately and concisely describe your problem, not your anticipated solution. Use terms appropriate to a Google search. Poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will be addressed according to the OP's experience in the forum: If you have less than 10 posts, expect (and respond to) a request to change your thread title. If you have 10 or more posts, expect your post to be locked, so you can start a new thread with an appropriate title.
To change a Title on your post, click EDIT then Go Advanced and change your title, if 2 days have passed ask a moderator to do it for you.
Hope that helps.
RoyUK
--------
If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need
For Excel consulting, free examples and tutorials visit Excel Consulting-Excel VBA
Check out the free Excel Toolbar
New members please read & follow the Forum Rules
Remember to mark your questions Solved and rate the answer(s)
Code Tags: Make your code easier for us to read
Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here
Hope that helps.
RoyUK
--------
If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need
For Excel consulting, free examples and tutorials visit Excel Consulting-Excel VBA
Check out the free Excel Toolbar
New members please read & follow the Forum Rules
Remember to mark your questions Solved and rate the answer(s)
Code Tags: Make your code easier for us to read
Welcome to the forum.
Please take a few minutes to read the forum rules, and then edit your post to add code tags and amend the title.
Thanks
Microsoft MVP - Excel
Entia non sunt multiplicanda sine necessitate
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks