extract data of a list from a list.

Anusuya12

New Member
Joined
Feb 27, 2011
Messages
27
I tried recording a macro to extract data of a list from a list.
But I could not succeed in it.
Can anyone help me out on this. I dont know how to attach my sample data here.

In Data sheet column A has some data like date,-1, and some more numbers
an Column B has numbers.
In Column AA there is a list of numbers.
Coding required is to extract the list of numbers in column AA
from cloumn A of the DATA sheet along with the number in column B
after 6 cells.
Example: Column AA39 has 5938791. The coding should identify this number from Column A (A33) along with the number in B39.
Note that all the numbers in column B wil be in this cell difference
of 6.
And extracted the list should come in Final Sheet.
Your assistance is much appreciated.
 
Last edited:

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Anusuya12,

Welcome to the MrExcel forum.


What version of Excel are you using?

You will generally get much more help (and faster) in this forum if you can post your small samples directly in the forum.

Please attach screenshots of your workbook or a sample workbook that accurately portrays your current workbook on one sheet, and what it should look like 'After' on another sheet.

This makes it much easier to see exactly what you want to do, as well as shows us whether there is a consistent number of rows between tables and such.

Here are three possible ways to post small (copyable) screen shots directly in your post:

Please post a screenshot of your sheet(s), what you have and what you expect to achieve, with Excel Jeanie HTML 4 (contains graphic instructions).
http://www.excel-jeanie-html.de/html/hlp_schnell_en.php

or
RichardSchollar’s beta HTML Maker -...his signature block at the bottom of his post

or
Borders-Copy-Paste



If you are not able to give us screenshots:

To get the most precise answer, it is best to upload/attach a sample workbook (sensitive data scrubbed/removed) that contains an example of your raw data on one worksheet, and on another worksheet your desired results.

The structure and data types of the sample workbook must exactly duplicate the real workbook. Include a clear and explicit explanation of your requirements.

You can upload your workbook to www.box.net and provide us with a link to your workbook.
 
Upvote 0
Thanks for your response.
http://www.box.net/shared/qz04urpagk
I have saved the sample data in the above link.
Details:
There is a list of numbers in column AA.
In Data Sheet Column A there are some data's which includes some of the numbers
in column AA.
In Data Sheet Column B there are some numbers again.
I need a coding to check if any of the number of column AA exists
in Column A, If yes then it should be copied to the next sheet along with
the number in B column after 6 cells.
I have highlighted one example in yellow,
If the number is in A33 then the corresponding number will be in
B39.
Now I need this A33 and B39 values to be copied and pasted in final
sheet.
Thanks.
 
Upvote 0
Anusuya12,


Sample raw data in worksheet Data:


Excel Workbook
ABAA
23861
323331
45711
5146981
6420921
7503911
8529871
9577021
10577101
11577291
12596871
132/7/2011597591
14-1630451
15630531
16205131
17224711
182/7/2011379051
19-1121441
20144731
21161611
22503271
232/7/2011621221
24-1658811
25775741
26786651
27825681
282/7/2011825761
29-1825841
30489331
31993321
321036701
3393879111036881
341036961
351037121
361037611
371335801
381494871
3949387911
Data





After the macro in worksheet Final:


Excel Workbook
AB
1
25298719
35772911
45975913
51214412
61447313
77757412
87866515
98256814
108257611
114893313
129933213
1393879114
14753448811
15514480915
168386323916
179001182451
189001182611
1990033690013
20
Final





Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).


1. Copy the below code, by highlighting the code and pressing the keys CTRL + C
2. Open your workbook
3. Press the keys ALT + F11 to open the Visual Basic Editor
4. Press the keys ALT + I to activate the Insert menu
5. Press M to insert a Standard Module
6. Where the cursor is flashing, paste the code by pressing the keys CTRL + V
7. Press the keys ALT + Q to exit the Editor, and return to Excel
8. To run the macro from Excel, open the workbook, and press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.


Code:
Option Explicit
Sub GetData()
' hiker95, 02/27/2011
' http://www.mrexcel.com/forum/showthread.php?t=532225
Dim w1 As Worksheet, w2 As Worksheet
Dim c As Range, FR As Long, NR As Long
Application.ScreenUpdating = False
Set w1 = Worksheets("Data")
Set w2 = Worksheets("Final")
For Each c In w1.Range("AA2", w1.Range("AA" & Rows.Count).End(xlUp))
  FR = 0
  On Error Resume Next
  FR = Application.Match(c, w1.Columns(1), 0)
  On Error Resume Next
  If FR > 0 Then
    NR = w2.Range("A" & Rows.Count).End(xlUp).Offset(1).Row
    w2.Cells(NR, 1) = c.Value
    w2.Cells(NR, 2).Value = w1.Cells(FR + 6, 2).Value
  End If
Next c
w2.Columns("A:B").AutoFit
w2.Activate
Application.ScreenUpdating = True
End Sub


Then run the GetData macro.
 
Upvote 0
Hi,

The data which I sent u was extracted after running the below code in an excel. This is a recorded macro.

And the coding you gave is after this step. Can you please let me know how to combine both the coding so that I have a single macro.

Sorry I should have given this information before hand.


Sub Report()<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>

Selection.TextToColumns Destination:=Range("A1"), DataType:=xlFixedWidth, _<o:p></o:p>
FieldInfo:=Array(Array(0, 1), Array(14, 1), Array(38, 1), Array(53, 1), Array(57, 1), _<o:p></o:p>
Array(60, 1), Array(64, 1), Array(73, 1), Array(88, 1), Array(105, 1), Array(127, 1), Array _<o:p></o:p>
(132, 1)), TrailingMinusNumbers:=True<o:p></o:p>
Cells.Select<o:p></o:p>
Cells.EntireColumn.AutoFit<o:p></o:p>
Columns("B:K").Select<o:p></o:p>
Selection.Delete Shift:=xlToLeft<o:p></o:p>
Columns("A:A").Select<o:p></o:p>
Selection.SpecialCells(xlCellTypeConstants, 2).Select<o:p></o:p>
Selection.EntireRow.Delete<o:p></o:p>
End Sub<o:p></o:p>
 
Upvote 0
Anusuya12,


Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).


1. Copy the below code, by highlighting the code and pressing the keys CTRL + C
2. Open your workbook
3. Press the keys ALT + F11 to open the Visual Basic Editor
4. Press the keys ALT + I to activate the Insert menu
5. Press M to insert a Standard Module
6. Where the cursor is flashing, paste the code by pressing the keys CTRL + V
7. Press the keys ALT + Q to exit the Editor, and return to Excel
8. To run the macro from Excel, open the workbook, and press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.


Code:
Sub ReportV2()
Selection.TextToColumns Destination:=Range("A1"), DataType:=xlFixedWidth, _
  FieldInfo:=Array(Array(0, 1), Array(14, 1), Array(38, 1), Array(53, 1), Array(57, 1), _
  Array(60, 1), Array(64, 1), Array(73, 1), Array(88, 1), Array(105, 1), Array(127, 1), Array _
  (132, 1)), TrailingMinusNumbers:=True
Cells.Select
Cells.EntireColumn.AutoFit
Columns("B:K").Select
Selection.Delete Shift:=xlToLeft
Columns("A:A").Select
Selection.SpecialCells(xlCellTypeConstants, 2).Select
Selection.EntireRow.Delete
''Sub GetData()
'' hiker95, 02/27/2011
'' http://www.mrexcel.com/forum/showthread.php?t=532225
Dim w1 As Worksheet, w2 As Worksheet
Dim c As Range, FR As Long, NR As Long
Application.ScreenUpdating = False
Set w1 = Worksheets("Data")
Set w2 = Worksheets("Final")
For Each c In w1.Range("AA2", w1.Range("AA" & Rows.Count).End(xlUp))
  FR = 0
  On Error Resume Next
  FR = Application.Match(c, w1.Columns(1), 0)
  On Error Resume Next
  If FR > 0 Then
    NR = w2.Range("A" & Rows.Count).End(xlUp).Offset(1).Row
    w2.Cells(NR, 1) = c.Value
    w2.Cells(NR, 2).Value = w1.Cells(FR + 6, 2).Value
  End If
Next c
w2.Columns("A:B").AutoFit
w2.Activate
Application.ScreenUpdating = True
End Sub


Then run the ReportV2 macro.
 
Upvote 0
Hi Hiker,
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p> </o:p>
I tried the above coding and it works for only for some of the reports. I found why it is not pulling the data correctly. It is because the difference of cells for the some of the data is not 6, it exceeds 6. And again there are subtotals in between. Hence I have decided to give you the dummy data of the whole sheet.
<o:p> </o:p>
Below is the link where I have saved the new sample.

http://www.box.net/shared/otq6hukphh
<o:p> </o:p>
I have pasted a report to column A of Data Worksheet.
<o:p> </o:p>
From this data I need the coding to identify only the account number listed in Final Worksheet and paste the total items number against the correct account number in cell highlighted in pink.

I have highlighted the account numbers and their total items number in blue color font for easy reference.
<o:p> </o:p>
And if the account number in Final sheet list is not there in Data sheet, then it should display as 0.
<o:p> </o:p>
Note that the report has four subdivisions in the sample attached – FORG, JIKAJIKIJUKKU, KADAMB and UTDFT for which the total is given separately. I have highlighted those totals in Lime.
Also it has grand total to it.
<o:p> </o:p>
<o:p> </o:p>
The respective total with the heading should be displayed in Data Sheet itself once macro completes.
<o:p> </o:p>
<o:p> </o:p>
Thanks in advance.
 
Upvote 0
Anusuya12,

I tried the above coding and it works for only for some of the reports. I found why it is not pulling the data correctly. It is because the difference of cells for the some of the data is not 6, it exceeds 6.


What is the max number greater then 6 that the difference could be?
 
Last edited:
Upvote 0
It cannot be defined as it differs from report to report. In the sample attached itself we have one account number with the difference of 18 and another with 19.

So we cannot go by line spacing.
 
Upvote 0

Forum statistics

Threads
1,224,542
Messages
6,179,421
Members
452,913
Latest member
JWD210

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