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:
Anusuya12,

In sheet Data, after your macro code, there is no list in column AA to be used to search.

I have worked out the code to search for the numbers in columns B and M for the new structure for worksheet Final.

But, I can not see the way to find the correct value in worksheet Data, column B, if the correct value is not 6 rows down from the found row in column A.

I could loop from 6 rows down to 19 rows down for the first value found in that range, but, this may not yield the correct number.


You may want to click on the Post Reply button, and just enter the word BUMP, then click on the Submit Reply button, and someone else will assist you.
 
Upvote 0

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Anusuya12,


Sample raw data before the macro:


Excel Workbook
A
1
2
3
41 APW System Esc. 7.5.10
5
6 Report 124 - Daily Status > 8 Days (On Friday) Run Date: 02/24/11 Page 1
7
8 Posted Date: From 1/1/70 To 02/16/11 Work Date: 02/24/11 Time: 7:10:53AM
9
10 Co. Name: CANJ CDFON Accounts Pool: 0500133850 ANU TEASFJK GHJNEKISNEMT
11
12 Dept: FORG
13
14
15**** **** ***** **** ***** **** ***** ** *********** **** ****** ******
16hfshdfh gfsgdfggdfg gfdgfdhdfhg sdgffd sgffgl
17
18 02/10/11 02/10/11 114,978.24 CR BO snjkosedio 175
19 -1 0500133850 01113 175
20
21
22 Message fdadfnjknljkhiundasfuihdsjhdiuhnkjufhnkjhohjnjknlkjoijkljpojlkjhoiup
23 asdfs,mfnkldnskfndkjnfdjfknnhjuhbyuvhggbvhkbhghbgkjyhiuhkjhyuhjhikhkuhjf
24 nl.khjljkjnlik
25
260500133850 ANU TEASFJK GHJNEKISNEMT
27
28
29 Credit Debit Net Total Total
30 Amount Items Amount Items Amount Amount Items
31
32 $114,978.24 1 $0.00 0 $-114,978.24 $114,978.24 1
33
Data





Excel Workbook
ABCD
3
4JIKAJIKIJUKKU
5asdffasdfafads
6fadsffadsfasdfads
71132145adsmfldjkf0
82234fadsfasd0
9315648745fadsfasd0
1041584851fsdf0
1151845132fdsaf0
12619644562vfsdagf0
137189452189vasdf0
1481658fasdfa0
1593216894adsmfldjkf0
161015628fadsfasd0
171112418741fadsfasd0
1812185964456fsdf0
191318745614874fdsaf0
201414987465vfsdagf0
21154187451vasdf0
2216487514fasdfa0
2317487456adsmfldjkf0
24181254548fadsfasd0
251921578fadsfasd0
262020157fsdf0
272110578fdsaf0
282221878vfsdagf0
292325631vasdf0
30242187fasdfa0
31259800112265vfsdagf0
32269800112251vasdf0
33272356988944fasdfa0
34TOTALS:0
35TOTALS:186
Final





After the macro:


Excel Workbook
AB
1
2
3
41
5
6
7
8
9
10
11
12
13
142/10/2011
15-1
16
17
18
19
20
21
22
23
24
25
261
27
28
29
30
31
32
33
Data





Excel Workbook
ABCD
3
4JIKAJIKIJUKKU
5asdffasdfafads
6fadsffadsfasdfads
71132145adsmfldjkf0
82234fadsfasd0
9315648745fadsfasd0
1041584851fsdf0
1151845132fdsaf0
12619644562vfsdagf0
137189452189vasdf0
1481658fasdfa0
1593216894adsmfldjkf0
161015628fadsfasd0
171112418741fadsfasd0
1812185964456fsdf0
191318745614874fdsaf0
201414987465vfsdagf0
21154187451vasdf0
2216487514fasdfa0
2317487456adsmfldjkf0
24181254548fadsfasd0
251921578fadsfasd0
262020157fsdf0
272110578fdsaf0
282221878vfsdagf0
292325631vasdf0
30242187fasdfa0
31259800112265vfsdagf7
32269800112251vasdf6
33272356988944fasdfa2
34TOTALS:15
35TOTALS:186
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 ReportV3()
' hiker95, 03/01/2011
' http://www.mrexcel.com/forum/showthread.php?t=532225
Dim w1 As Worksheet, w2 As Worksheet
Dim AArea As Range, SR As Long, ER As Long
Dim c As Range, FR As Long, a As Long
Application.ScreenUpdating = False
Set w1 = Worksheets("Data")
Set w2 = Worksheets("Final")
w1.Columns(1).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
w1.UsedRange.Columns.AutoFit
w1.Columns("B:K").Delete
w1.Columns(1).SpecialCells(xlCellTypeConstants, 2).EntireRow.Delete
For Each AArea In w2.Range("A1", w2.Range("A" & Rows.Count).End(xlUp)).SpecialCells(xlCellTypeConstants).Areas
  With AArea
    SR = .Row
    ER = SR + .Rows.Count - 1
    For Each c In w2.Range("B" & SR & ":B" & ER)
      FR = 0
      On Error Resume Next
      FR = Application.Match(c, w1.Columns(1), 0)
      On Error Resume Next
      If FR > 0 Then
        
        '*****c.Offset(, 2).Value = w1.Cells(FR + 6, 2).Value
        
        For a = FR + 6 To FR + 19 Step 1                  '***** 6 thru 19
          If w1.Cells(a, 2) <> "" Then
            c.Offset(, 2).Value = w1.Cells(a, 2).Value
            Exit For
          End If
        Next a
        
        If c.Offset(, 2).Value = "" Then c.Offset(, 2).Value = 0
      End If
    Next c
  End With
Next AArea

For Each AArea In w2.Range("K1", w2.Range("K" & Rows.Count).End(xlUp)).SpecialCells(xlCellTypeConstants).Areas
  With AArea
    SR = .Row
    ER = SR + .Rows.Count - 1
    For Each c In w2.Range("L" & SR & ":L" & ER)
      FR = 0
      On Error Resume Next
      FR = Application.Match(c, w1.Columns(1), 0)
      On Error Resume Next
      If FR > 0 Then
        
        '*****c.Offset(, 2).Value = w1.Cells(FR + 6, 2).Value

        For a = FR + 6 To FR + 19 Step 1                  '***** 6 thru 19
          If w1.Cells(a, 2) <> "" Then
            c.Offset(, 2).Value = w1.Cells(a, 2).Value
            Exit For
          End If
        Next a

        If c.Offset(, 2).Value = "" Then c.Offset(, 2).Value = 0
      End If
    Next c
  End With
Next AArea
w2.Activate
Application.ScreenUpdating = True
End Sub


Then run the ReportV3 macro.
 
Upvote 0
Now this is working.
I have tested this macro with 10 reports and its pulling the data's correctly.

Thanks.
 
Upvote 0
Conditionally Insert a row

Hey Hiker,

How are you??

I need your assistance. Am looking for macro coding. See below for details.

I have attached the sample data in the below link.

http://www.box.net/shared/2j2gnpayn2

In Sheet 1 there are two columns as SUB and SHADOW.
In Sheet 2 there are a set of datas, out of which I have colored
three of the numbers in Data 1 column. You can see this numbers in
Sheet 1 under SUB column as well (the colored cell).

Macro should see all the numbers in Data 1 column of Sheet 2 and if
the number exists in SUB column of Sheet 1 then it should insert a
line and the data 1 column should be filled with the corresponding
SHADOW number and rest of the column should be the duplicate of the
above entry.

I have attached a sample for the expected result of the macro in
Sheet 2 under the original data.
 
Upvote 0
Anusuya12,


Sample raw data:


Excel Workbook
AB
1SUBSHADOW
26007960329
360027
460028
560029
660030
760399
86070260077
960703
1060704
1160705
126011060109
1360112
1460113
1560795
1660799
176078060122
1860781
1960782
206029460087
2160295
2260296
2360334
246033960343
2560340
2660240
2760241
2860802
296311160801
3063112
3163113
3263114
3360800
34
Sheet1





Excel Workbook
ABCDEFGHIJ
1Data 1Data 2Data 3Data 4Data 5Data 6Data 7Data 8Data 9Data 10
250426int4/16/20114/16/201126.23
360532int4/16/20114/17/2011125.56
459621div4/16/20114/18/2011245.59
560703div4/16/20114/18/2011245.59
615326div4/16/20114/19/2011125.5
720546int4/16/20114/20/2011362.4
860780int4/16/20114/20/2011362.4
960339int4/16/20114/20/2011362.4
10
11
12
13
Sheet2





After the macro on worksheet Sheet2:


Excel Workbook
ABCDEFGHIJ
1Data 1Data 2Data 3Data 4Data 5Data 6Data 7Data 8Data 9Data 10
250426int4/16/20114/16/201126.23
360532int4/16/20114/17/2011125.56
459621div4/16/20114/18/2011245.59
560703div4/16/20114/18/2011245.59
660077div4/16/20114/18/2011245.59
715326div4/16/20114/19/2011125.5
820546int4/16/20114/20/2011362.4
960780int4/16/20114/20/2011362.4
1060122int4/16/20114/20/2011362.4
1160339int4/16/20114/20/2011362.4
1260343int4/16/20114/20/2011362.4
13
Sheet2





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 CopySHADOW()
' hiker95, 04/16/2011
' http://www.mrexcel.com/forum/showthread.php?t=532225&page=2
Dim w1 As Worksheet, w2 As Worksheet
Dim LR As Long, a As Long, aa As Long, FR As Long
Application.ScreenUpdating = False
Set w1 = Worksheets("Sheet1")
Set w2 = Worksheets("Sheet2")
LR = w2.Cells(Rows.Count, 1).End(xlUp).Row
For a = LR To 2 Step -1
  FR = 0
  On Error Resume Next
  FR = Application.Match(w2.Cells(a, 1), w1.Columns(1), 0)
  On Error GoTo 0
  If FR <> 0 Then
    w2.Rows(a + 1).Insert
    w2.Rows(a).Copy w2.Rows(a + 1)
    For aa = FR To 2 Step -1
      If w1.Cells(aa, 1).Offset(, 1) <> "" Then
        w2.Cells(a + 1, 1).Value = w1.Cells(aa, 1).Offset(, 1).Value
        Exit For
      End If
    Next aa
  End If
Next a
w2.Activate
Application.ScreenUpdating = True
End Sub


Then run the CopySHADOW macro.
 
Upvote 0
Thanks Hiker... That works great.. I have little changes to match my original data... Is there a place where I could learn how to write coding I just know to record it... Am now learning by browsing some sites.
 
Upvote 0
Need your Assistance for one more macro

Need your Assistance for one more macro Hiker... Hope am not troubling you....
When I was browsing sites I learnt how to convert excel data to a template in word.

Below is the link where I have saved my Excel file with the macro.

http://www.box.net/shared/0qmvopqoufhttp://www.box.net/shared/ocppqax5t4

When you run FINAL macro it saves word document with the template (with the data in Formated Sheet).

As Specified in the macro the word document saves in the name as "File and the sequential number".

But I need the documents to be named with the data in Column H of the Formatted Data Sheet sequentially. Also the data in the word document are not formatted properly.

The word document looks like this after the macro.

http://www.box.net/shared/a2bpvdhesu

But I need the Word to show my data in the format below.

http://www.box.net/shared/8hblc2k9qo


Is there a possibility to do this? :confused:

Sorry again to bother you. :(

Your help is much appreciated :)

Anusuya12.
 
Upvote 0
Anusuya12,

Is there a place where I could learn how to write coding I just know to record it...


Training / Books / Sites:

MrExcel's Products: Books, CDs, Podcasts Discuss topics related to Holy Macro! Products: Learn Excel from MrExcel, VBA and Macros for Microsoft Excel,Holy Macro! It's 2500 VBA Examples CD, Guerilla Data Analysis Using Microsoft Excel and Excel Knowledge Base CD and the MrExcel Podcasts.
http://www.mrexcel.com/forum/forumdisplay.php?f=19

How to Learn to Write Macros
http://articles.excelyogi.com/playin...ba/2008/10/27/

How to use the macro recorder
http://articles.excelyogi.com/

Click here and scroll down to Getting Started with VBA.
http://www.datapigtechnologies.com/ExcelMain.htm

If you are serious about learning VBA try
http://www.add-ins.com/vbhelp.htm

Excel Tutorials and Tips - VBA - macros - training
http://www.mrexcel.com/articles.shtml

See David McRitchie's site if you just started with VBA
http://www.mvps.org/dmcritchie/excel/getstarted.htm

Debra Dalgleish has some notes how to implement macros here:
Excel VBA -- Adding Code to a Workbook
http://www.contextures.com/xlvba01.html

David McRitchie has an intro to macros:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

Ron de Bruin's intro to macros:
http://www.rondebruin.nl/code.htm

Creating custom functions
http://office.microsoft.com/en-us/excel/HA011117011033.aspx

Writing Your First VBA Function in Excel
http://www.exceltip.com/st/Writing_Your_First_VBA_Function_in_Excel/631.html

http://www.excel-vba.com/
http://www.mvps.org/dmcritchie/excel/getstarted.htm
http://www.exceltip.com/excel_links.html

(livelessons video)
Excel VBA and Macros with MrExcel
ISBN: 0-7897-3938-0
http://www.amazon.com/Excel-Macros-M...7936479&sr=1-1

http://www.youtube.com/user/ExcelIsFun#g/search

http://www.xl-central.com/index.html

http://www.datapigtechnologies.com/ExcelMain.htm

Dependent validation lists. Debra has a neat little tutorial here.
http://www.contextures.com/xlDataVal02.html

Data Validation > Drop-Down Lists - Dependent
http://www.bettersolutions.com/excel/EGH188/QE229212022.htm

Cascading queries
http://www.tushar-mehta.com/excel/ne...ing_dropdowns/

http://www.contextures.com/xlDataVal05.html
http://www.contextures.com/xlDataVal08.html#Larger

Excel Data Validation - Add New Items
http://www.contextures.com/excel-data-validation-add.html

Programming The VBA Editor - Created by Chip Pearson at Pearson Software Consulting LLC
This page describes how to write code that modifies or reads other VBA code.
http://www.cpearson.com/Excel/vbe.aspx

Locating files containing VBA
Searching Files in Subfolders for VBA code string:
http://www.dailydoseofexcel.com/arch...a-code-string/

http://www.pcreview.co.uk/forums/thread-978054.php

Excel 2003 Power Programming with VBA, by John Walkenbach

VBA and Macros for Microsoft Excel, by Bill Jelen "Mr.Excel" and Tracy Syrstad

Excel Hacks 100 Industrial-Strength Tips & Tools, by David & Traina Hawley

VBA and Macros for Microsoft Excel 2007, by Bill Jelen "Mr.Excel" and Tracy Syrstad

Excel 2007 Book: you can try this...there is a try before you buy ebook available at this link…
http://www.mrexcel.com/learnexcel2.shtml

DonkeyOte: My Recommended Reading:
Volatility
http://www.decisionmodels.com/calcsecretsi.htm

Sumproduct
http://www.xldynamic.com/source/xld.SUMPRODUCT.html

Introduction to Array Formulas
http://www.xtremevbtalk.com/showthread.php?t=296012

Using Pivot Tables and Pivot Charts in Microsoft Excel
http://peltiertech.com/Excel/Pivots/pivotstart.htm

A List of Pivot Table links at Jon Peltier's site (contributed by Debra Dalgleish) is here:
http://peltiertech.com/Excel/Pivots/pivotlinks.htm

Email from XL - VBA & Outlook VBA
http://www.rondebruin.nl/sendmail.htm
http://www.outlookcode.com/article.aspx?ID=40

Excel Function Dictionary
http://www.xlfdic.com/

Excel 2007 function name translations
http://www.piuha.fi/excel-function-name-translation/

Dynamic Named Ranges
http://www.contextures.com/xlNames01.html

Where to paste code in VBE VBA
Introducing the Excel VBA Editor
http://www.ask.com/web?qsrc=2417&o=101881&l=dis&q=Where+to+paste+code+in+the+Excel+VBA+Editor

VBA for Excel (Macros)
http://www.excel-vba.com/excel-vba-contents.htm

VBA Lesson 11: VBA Code General Tips and General Vocabulary
http://www.excel-vba.com/vba-code-2-1-tips.htm

Excel VBA -- Adding Code to a Workbook
http://www.contextures.com/xlvba01.html

Basics of array formulas
http://www.youtube.com/view_play_lis...7E7E9CA63304D3

Array formula data extract formulas
http://www.youtube.com/watch?v=Tp7I5u1MqiM
http://www.youtube.com/watch?v=R5ZWAiNJLNo
http://www.youtube.com/watch?v=132ZdpxBm1U

How to create Excel Dashboards
http://www.contextures.com/excel-dashboards.html
http://chandoo.org/wp/excel-dashboards/

Excel Dashboard / Scorecard Ebook
http://www.qimacros.com/excel-dashboard-scorecard.html

Unique Record Counting and Data Extract formulas
http://www.youtube.com/watch?v=uUrI8hoj8BA

And, as your skills increase, try answering posts on sites like:
http://www.mrexcel.com/
http://www.excelforum.com/
http://www.exceltip.com/exceltips.php
http://www.ozgrid.com/
 
Upvote 0

Forum statistics

Threads
1,224,550
Messages
6,179,463
Members
452,915
Latest member
hannnahheileen

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