Macro to retrieve data and to return in tabular form

Madzark

New Member
Joined
May 8, 2016
Messages
17
Hello guys,

I would like to run a macro that allows me to group some data that is scattered into tabular form. In particular, the information to be retrieved is "anticipated" by a number label contained in the cell immediately to the left of the relevant data to be retrieved. In addition, these labels are contained in definied columns.

For example:

ABCDE
11.000
22.000
33.000
44.000510.000

<tbody>
</tbody>


AB
11.000
22.000
33.000
44.000
510.000

<tbody>
</tbody>

In this case, the macro should search all the value reported between the labels from 1 to 5 and return these values in a different sheet with the relevant labels.

This would really help me a lot because I have more than 500 labels (and as much information) that I should convert into the table format.

Many thanks!
 
Last edited:
You are right. There is a jump from 107 to 111. I tried to make a new retrieve_data() macro starting with n=111, but it doesn't work. How can I solve this? :)


Two options:

- Can you at least say in which initial column the data will start?That is, in your example the initial column is E, it will always start in E. With that I could change the way to search, then the macro would search by columns, if 3 does not exist, it does not matter, the macro would continue with the next column.

- Or put a finite number, which starts at 1 and ends at 1000. That way if there is no number that continues until it reaches 1000.


Try second option:
Change 1000 for the maximum number to reach

Code:
Sub retrieve_data()
  Dim sh2 As Worksheet, i As Long, f As Range
  Application.ScreenUpdating = False
  Set sh2 = Sheets("Sheet2")
  sh2.Cells.ClearContents
  For i = 1 To [COLOR=#0000ff][B]1000[/B][/COLOR]
    Set f = Sheets("Sheet1").Cells.Find(i, , xlValues, xlWhole)
    If Not f Is Nothing Then
      If f.Offset(, 1).Value <> "" Then
        sh2.Cells(i, "A").Value = i
        sh2.Cells(i, "B").Value = f.Offset(, 1)
      End If
    End If
  Next
End Sub
 
Upvote 0

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.

Forum statistics

Threads
1,215,343
Messages
6,124,400
Members
449,156
Latest member
LSchleppi

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