+ Reply to Thread
Results 1 to 4 of 4

Basic Macro query

  1. #1
    Registered User
    Join Date
    09-24-2009
    Location
    london
    MS-Off Ver
    Excel 2003
    Posts
    1

    Basic Macro query

    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 03:48 PM.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Basic Macro query

    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
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Basic Macro query

    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

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Basic Macro query

    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
    Entia non sunt multiplicanda sine necessitate

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1