returning values

Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

Forum home » Delegate support and help forum » Microsoft Excel Training and help » Returning values

Returning values

resolvedResolved · High Priority · Version 2003

Li-kim has attended:
Excel Intermediate course
Excel Advanced course
Excel VBA Intro Intermediate course

Returning values

I have a very long list of numbers and text in the table. Some of the numbers and text may be duplicated. There are formulas to sort out some of these values in adjoining columns too.

In 20 rows of a separate table (on the same sheet), I want to list the top 20 largest values from the 1st/above-mentioned list, as well as the corresponding values or text in the same rows where these largest values occur.

VLOOKUP, INDEX and MATCH are not exactly working for this question, or else I am using them wrongly. I started by using LARGE (e.g. =LARGE($J:$J,7)) to get the top 20 largest values but cannot use INDEX and MATCH because these top 20 largest values (may) occur several times in the sheet.

RE: returning values

Hi Li-Kim

Thank you for your question

Can you clarify a couple of points for me please

Do you wish to return the top 10 values including or excluding duplicates?

If you want it without duplicates is the data in rows the same for each value? That is is the whole row duplicated or just the value. If it is just the value, what criteria do you use to determine which of the duplicate rows to copy?

Thanks

Stephen

RE: returning values

Hello Stephen,

Thanks for replying. I would appreciate your help very much.

The top 20 values can include duplicates.

E.g. if the list is the following values (it is much longer in reality):
1475
6237
1803
6237
7436
5358
4199
2864
3904
630
5358
383
1094
1127
1960
6237
1803
1475
977
630
5358
6237
8929
3043
1925
1613
3265
648
1034
1362

then I would like the following returned:
8929
7436
6237
6237
6237
6237
5358
5358
5358
4199
3904
3265
3043
2864
1960
1925
1803
1803
1613
1475

with, for each value, the corresponding data in adjoining cells of the same row.

RE: returning values

Hi Li-Kim

The easiest way to do this would be to create a macro that sorts the data in descending order by numbers (so that the largest numbers are at the top)and then simply copies the first 20 rows to your new sheet.

You could record a macro to do this, but it would be fiddly. It would be a simple matter to write the macro in VBA. I can do that for you, but first I need to know the following.

1. The name of the sheet that contains the data
2. The name of the sheet where you want the summary to go
3. The column in the source sheet that contains the numbers you are sorting on

Thanks

Stephen

RE: returning values

Hello Stephen,

Thanks. I understand what you mean. I have also tried nested IF functions fore returning the nth largest values but it does not work if there are dublicates in these values i.e. the lookup function returns the same row data for duplicate values.

So for the macro:
1. Pages
2. EDITORIAL DASHBOARDS
3. F:F

For #3 above, the name/header in that column, i.e. the text in cell F1, is Visits. I can define a name for that column if required.

Thanks
Li Kim

RE: returning values

Hi Li Kim

To run the macro you need to create a new module in the VBE.

To do this open your workbook and close down all other workbooks. Then press ALT F11. In the resulting window click on the insert menu and select "module"

In the code window (Large one on the right) paste the following code.

Sub CopyData()

Dim intRowCount As Integer
Dim intColumnCount As Integer
Dim intColumns As Integer

Application.ScreenUpdating = False

Sheets("Pages").Select

Range("A2").CurrentRegion.Sort key1:=Range("F1"), order1:=xlDescending

intColumns = Sheets("Pages").Range("A1").CurrentRegion.Columns.Count

For intRowCount = 1 To 21

Sheets("Pages").Select

Range(Cells(intRowCount, 1), Cells(intRowCount, intColumns)).Select

Selection.Copy

Sheets("Editorial Dashboards").Select

Cells(intRowCount, 1).Select

ActiveSheet.Paste



Next intRowCount

Application.CutCopyMode = False
Range("A1").Select


End Sub


You will then have a macro called CopyData which you can run in the normal way. If you have problems it will be because your sheet does not match all the assumptions I have made. For example I have assumed that the data starts in cell A1.

You could try tweaking the code, but if you have major problems you could just email me the workbook and I will fix the problems. My email is stephen@stl-training.co.uk


Regards

Stephen

Thu 26 Mar 2009: Automatically marked as resolved.


 

Excel tip:

Hide data in Excel Worksheets

Let's say you have some data in cell 'C5' you would like to hide from the casual viewer.

Click cell 'C5' to select it.

Click the 'Format' menu, select 'Cells'. When the 'Format Cells' dialogue box opens, click the 'Numbers' tab (if necessary), then select 'Custom' from the 'Category' list.

Double-click the 'Type' entry box and type three semi-colons: ";;;"

Click 'OK' to close the dialogue box and accept the new formatting.

The data in cell 'C5' disappears. It's still there and will work in calculations, but it isn't visible.

If you need to check the data, just click the blank cell and the contents appear in the 'Formula bar'.

View all Excel hints and tips


Server loaded in 0.08 secs.