+ Reply to Thread
Results 1 to 4 of 4

Thread: Transpose column to row but remove / delete certain values

  1. #1
    Registered User
    Join Date
    04-14-2011
    Location
    Bay Area, CA
    MS-Off Ver
    Excel 2007
    Posts
    1

    Transpose column to row but remove / delete certain values

    Hi,

    I have seen variations of this discussed, but I didn't seem to find a discussion of my specific problem (and if I've somehow missed it, please point me in the direction of it).

    So, I have a column of values that I would like to transpose to a row. That's easy enough. However, the issue is that I would like to remove (delete) certain values such that they do NOT show up in my transposed row.

    For instance, my values are of the form:
    1XX
    1XX
    2XX
    2XX
    2XX
    3XX
    3XX
    4XX
    4XX
    4XX
    4XX

    Where, "XX" can be any number from 0-9.

    I want to transpose that, but, let's say, remove all values starting w/ 3, so the result would be:

    1XX 1XX 2XX 2XX 2XX 4XX 4XX 4XX 4XX

    Now, if it's easy to do it w/ a "hard coded" value of 3, I will be happy w/ that.

    However, what would be "nice" is to have the freedom to choose which beginning number I want to remove (to have a more robust macro).

    So, for instance, if I want it to remove all values starting with 1, or 2, or 3, or 4, etc. I'm assuming that would require some sort of user interface window to have the user type in the starting number (in the example above, it would be 3), and then the code would remove all cells which start with 3.

    If that is too difficult, the hard coded version will do exactly what I need.

    Also, if something like this can be achieved just be using Excel's built-in functionality without any programming, that would be great too (just point me to the proper function name & I'll look up the help for it).

    TIA,
    Rob

  2. #2
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    3,788

    Re: Transpose column to row but remove / delete certain values

    In this you specify the number to exclude, the starting range and first cell where results should go:
    Sub x()
    
    Dim n As Long, rIn As Range, rOut As Range, v, w, i As Long, j As Long
    
    With Application
        n = .InputBox("Number to exclude?", Type:=1)
        Set rIn = .InputBox("Starting range?", Type:=8)
        Set rOut = .InputBox("Output cell?", Type:=8)
    End With
    
    v = rIn.Value
    ReDim w(1 To UBound(v))
    
    For i = LBound(v) To UBound(v)
        If Left(v(i, 1), 1) <> n Then
            j = j + 1
            w(j) = v(i, 1)
        End If
    Next i
    
    rOut.Resize(, j) = w
    
    End Sub

  3. #3
    Valued Forum Contributor MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2010
    Posts
    5,300

    Re: Transpose column to row but remove / delete certain values

    Hi Rob and welcome to the forum,

    I'd do this problem by first using an Advanced Filter to another area or the sheet and then copy and paste transpose.

    See some examples at:
    http://www.contextures.com/xladvfilter01.html
    http://www.excelfunctions.net/ExcelAdvancedFilter.html

    I hope this helps.
    One test is worth a thousand opinions.
    Click the * below to say thanks.

  4. #4
    Forum Guru Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    5,590

    Re: Transpose column to row but remove / delete certain values

    If I am reading you correctly, this might be a formula solution
    With your values in A2 down

    Create a dynamic named range
    Name:= "Values"
    Refers to:=
    =Sheet1!$A$2:INDEX(Sheet1!$A:$A,COUNT(Sheet1!$A:$A)+1,1)
    In C1 Put the leading digit for the values you want to remove

    In D2 this array formula
    =IFERROR(IF(ISERROR(INDEX(Values, SMALL(IF((INT(Values/10)=$C$1)+ISERROR(Values), "", ROW(Values)-MIN(ROW(Values))+1), COLUMN(A1)))),"",INDEX(Values, SMALL(IF((INT(Values/10)=$C$1)+ISERROR(Values), "", ROW(Values)-MIN(ROW(Values))+1), COLUMN(A1)))),"")
    Confirm with Ctrl +Shift+Enter not just Enter.
    Drag across as required.
    Attached Files Attached Files
    If you need any more information, please feel free to ask.

    However, if this takes care of your needs, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED. It helps everybody! ....
    Also
    If you are satisfied by any members response to your problem please consider using the small Star icon botom left of thier post to show your appreciation.

+ 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.2.0