+ Reply to Thread
Results 1 to 7 of 7

how to remove numbers in a column that include numbers in another column?

Hybrid View

FZ1 how to remove numbers in a... 05-29-2024, 03:03 PM
alansidman Re: how to remove numbers in... 05-29-2024, 03:58 PM
FZ1 Re: how to remove numbers in... 05-29-2024, 05:55 PM
alansidman Re: how to remove numbers in... 05-29-2024, 06:16 PM
daboho Re: how to remove numbers in... 05-29-2024, 08:07 PM
FZ1 Re: how to remove numbers in... 05-30-2024, 11:59 AM
jindon Re: how to remove numbers in... 05-29-2024, 10:04 PM
  1. #1
    Registered User
    Join Date
    01-15-2018
    Location
    Hudson, OH
    MS-Off Ver
    Office 365 Business
    Posts
    12

    how to remove numbers in a column that include numbers in another column?

    I have 2 columns of numbers, I'll call them column A&B. Some numbers are in both columns. I want to remove any numbers in column B that are also in Column A. It seems easy enough but I can't figure it out. I don't care if it's in excel or a macro, probably will end up as part of a macro that i'll put in a loop because the length of the columns varies

    using the numbers below, the final result should be column B except with 1,7 & 21 removed

    Column A:
    1
    4
    7
    9
    13
    16
    19
    20
    21

    Column B
    1
    2
    5
    7
    21
    24
    29
    34
    36
    38
    45

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2506 Win 11
    Posts
    24,767

    Re: how to remove numbers in a column that include numbers in another column?

    A power query solution

    let
        T1 = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
        T2 = Excel.CurrentWorkbook(){[Name="Table2"]}[Content],
        MQ = Table.NestedJoin(T1, {"Column A:"}, T2, {"Column B"}, "Table2", JoinKind.RightAnti),
        #"Expanded Table2" = Table.ExpandTableColumn(MQ, "Table2", {"Column B"}, {"Column B"}),
        #"Removed Columns" = Table.RemoveColumns(#"Expanded Table2",{"Column A:"})
    
    in
        #"Removed Columns"
    Excel 2016 (Windows) 64 bit
    A
    B
    C
    D
    1
    Column A: Column B Column B
    2
    1
    1
    2
    3
    4
    2
    5
    4
    7
    5
    24
    5
    9
    7
    29
    6
    13
    21
    34
    7
    16
    24
    36
    8
    19
    29
    38
    9
    20
    34
    45
    10
    21
    36
    11
    38
    12
    45
    Sheet: Sheet1

    Power Query is a free AddIn for Excel 2010 and 2013, and is built-in functionality from Excel 2016 onwards (where it is referred to as "Get & Transform Data").

    It is a powerful yet simple way of getting, changing and using data from a broad variety of sources, creating steps which may be easily repeated and refreshed. I strongly recommend learning how to use Power Query - it's among the most powerful functionalities of Excel.

    - Follow this link to learn how to install Power Query in Excel 2010 / 2013.

    - Follow this link for an introduction to Power Query functionality.

    - Follow this link for a video which demonstrates how to use Power Query code provided.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Registered User
    Join Date
    01-15-2018
    Location
    Hudson, OH
    MS-Off Ver
    Office 365 Business
    Posts
    12

    Re: how to remove numbers in a column that include numbers in another column?

    Thank you, I have never heard of power query, I'll do some research and try to figure this out. Wish there was a simpler way

  4. #4
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2506 Win 11
    Posts
    24,767

    Re: how to remove numbers in a column that include numbers in another column?

    It is rather simple if you give yourself a chance to spend time with it. It can all be achieved with point and click in the User Interface. No coding is required to get started.

  5. #5
    Forum Expert
    Join Date
    11-28-2015
    Location
    indo
    MS-Off Ver
    2016 64 bitt
    Posts
    1,513

    Re: how to remove numbers in a column that include numbers in another column?

    Sub perhab()
    Dim a, b, c, i As Long, dic As Object
    a = Range("A1:A" & Cells(Rows.Count, 1).End(3).Row).Value
    b = Range("B1:B" & Cells(Rows.Count, 2).End(3).Row).Value
    ReDim c(1 To 2)
    c(1) = a: c(2) = b
    Set dic = CreateObject("Scripting.Dictionary")
    For i = 1 To 2
     For j = 1 To UBound(c(i))
       If Not dic.Exists(c(i)(j, 1)) Then
          dic.Add c(i)(j, 1), Array(IIf(i = 2, i, ""), c(i)(j, 1))
       Else
          dic.Remove c(i)(j, 1)
       End If
     Next j
    Next i
    With Range("C1")
      .Resize(dic.Count, 2).Value = Application.Index(dic.Items, 0, 0)
      .EntireColumn.SpecialCells(2, 1).Resize(, 2).ClearContents
    End With
    End Sub
    ANOTHER WAY
    Sub anotherWay()
    Dim a, i As Long
    With Range("A1:A" & Cells(Rows.Count, 1).End(3).Row)
      a = .Value
        For i = 1 To UBound(a)
         If Application.CountIf(Range("B:B"), a(i, 1)) > 0 Then
           a(i, 1) = ""
         End If
        Next i
      .Value = a
      On Error Resume Next:   .SpecialCells(4).Delete Shift:=xlUp: On Error GoTo 0
    End With
    End Sub
    Last edited by daboho; 05-30-2024 at 12:45 AM.
    "Presh Star Who has help you *For Add Reputation!! And mark case as Solve"

  6. #6
    Registered User
    Join Date
    01-15-2018
    Location
    Hudson, OH
    MS-Off Ver
    Office 365 Business
    Posts
    12

    Re: how to remove numbers in a column that include numbers in another column?

    Sub anotherWay()
    Dim a, i As Long
    With Range("A1:A" & Cells(Rows.Count, 1).End(3).Row)
      a = .Value
        For i = 1 To UBound(a)
         If Application.CountIf(Range("B:B"), a(i, 1)) > 0 Then
           a(i, 1) = ""
         End If
        Next i
      .Value = a
      On Error Resume Next:   .SpecialCells(4).Delete Shift:=xlUp: On Error GoTo 0
    End With
    End Sub
    This worked, thank you!! people on this board are good
    Last edited by FZ1; 05-30-2024 at 12:03 PM.

  7. #7
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: how to remove numbers in a column that include numbers in another column?

    Try
    Sub test()
        With [a1].CurrentRegion
            .Columns(2).Value = Evaluate("if(isnumber(match(" & .Columns(2).Address & "," & _
            .Columns(1).Address & ",0)),""#n/a""," & .Columns(2).Address & ")")
            On Error Resume Next
            .Columns(2).SpecialCells(2, 16).Delete xlShiftUp
            On Error GoTo 0
        End With
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Remove Numbers from Column
    By ionelz in forum Excel General
    Replies: 5
    Last Post: 11-22-2021, 08:17 PM
  2. Remove numbers from a column
    By Canbeaver in forum Excel General
    Replies: 6
    Last Post: 01-15-2018, 11:16 AM
  3. remove numbers from column
    By chriswrcg in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 07-21-2017, 08:57 AM
  4. How to remove numbers from a column but keep letters?
    By kairalynn in forum Excel General
    Replies: 9
    Last Post: 09-11-2014, 08:15 PM
  5. [SOLVED] How do I remove the following from a column of numbers: *0
    By rhouse in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 04-18-2013, 06:44 PM
  6. Remove numbers in Column A from Column B
    By nobermaster in forum Excel - New Users/Basics
    Replies: 2
    Last Post: 06-27-2012, 06:12 PM
  7. [SOLVED] I need to remove asterisks from a column of numbers
    By Kevin Mack in forum Excel General
    Replies: 1
    Last Post: 11-29-2005, 02:15 AM

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