VBA Code to Extract data

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,561
Office Version
  1. 2021
Platform
  1. Windows
I have a spreadsheet with account numbers in Col A & C. I would like a macro that will extract all numbers that are in Col A C to Col E for eg if 7802 appears in Col A, but But not in Col C, it must be extracted to Col E as it is unique. I also need the heading from each column where the number is being extracted from

I have extracted the unique numbers manually to show what the extraction must look like.

Your assistance is most appreciated

http://windowssecrets.com/forums/showthread.php/147057-Macro-to-compare-number


Comparing Account Numbers.xls
ABCDEF
1InputTaxAccountNumbersCOSAccountNumberAccountNumbersNotMatchedType
2700170017809COSAccountNumber
3780278097802InputTaxAccountNumbers
4790379037401InputTaxAccountNumbers
5732573257400COSAccountNumber
6740174007503InputTaxAccountNumbers
7750375007500COSAccountNumber
876027602InputTaxAccountNumbers
975947594InputTaxAccountNumbers
10
Sheet1
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Hi,
try the macro:
Code:
Sub aaa()
Dim NoDupes As New Collection, tbl()
Dim a&, c&, i&, x&

a = Cells(Rows.Count, 1).End(xlUp).Row
c = Cells(Rows.Count, 3).End(xlUp).Row

For i = 2 To a
   On Error Resume Next
   If Application.CountIf(Range("C2:C" & c), Cells(i, 1).Value) = 0 Then
   NoDupes.Add 1, CStr(Cells(i, 1).Value)
   If Err.Number = 0 Then
     x = x + 1
     ReDim Preserve tbl(1 To x)
     tbl(x) = Cells(i, 1).Value
   End If
   End If
Next i

Cells(2, 5).Resize(UBound(tbl)) = Application.Transpose(tbl)
End Sub
Best regards.
 
Upvote 0
Hey hurgadion, that code won't do what he wants.
Try this,

Code:
Sub d()  Dim c01 As Range, c02, rng, rng1, lr, lr1, iRow, cel, lr2
   Application.ScreenUpdating = 0
    lr = Cells(Rows.Count, 1).End(xlUp).Row
    lr1 = Cells(Rows.Count, 3).End(xlUp).Row
    lr2 = Cells(Rows.Count, 5).End(xlUp).Row + 1
      If lr > lr1 Then
        cel = lr
      Else
        cel = lr1
      End If
    iRow = lr2
     For i = 2 To cel
      For y = 1 To 3 Step 2
        Set c01 = Cells(i, y)
         If y = 1 Then
          Set c02 = Range("C2:C" & lr1).Find(c01, , xlValues, xlWhole)
         Else
           Set c02 = Range("A2:A" & lr).Find(c01, , xlValues, xlWhole)
         End If
            If c02 Is Nothing Then
             If c01 <> vbNullString Then
              Cells(iRow, 5).Value = c01
                If y = 1 Then
                  Cells(iRow, 6).Value = Cells(1, 1).Value
                Else
                  Cells(iRow, 6).Value = Cells(1, 3).Value
                End If
              iRow = iRow + 1
             End If
            End If
      Next y
     Next i
   Application.ScreenUpdating = 1
End Sub
 
Upvote 0
Hi Guys

Thanks for the help. ***anDave, your code does exactly what I require. This is much appreciated
 
Upvote 0
@hurgadion, I agree that using an array would be much faster. As always, there is many ways to skin a cat.:cool:
Cheers
 
Upvote 0
VBA CODE TO EXTRACT DATA:
Hey guys i am currently doing my internship in productiion planning dept and i am building a excel model. i have daily MIS report from SAP which i need to use as input for my excel model. once i give the input my model should tell me the required time to complete the current and new orders.
kindly share the code required for extracting data from MIS report
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,276
Members
449,075
Latest member
staticfluids

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top