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

lookup function

ResolvedVersion 2010

Adrian has attended:
Excel VBA Introduction course
Excel VBA Intermediate course
Excel Intermediate course

Lookup Function

Hi

I have a table of data, lets say A1->E7 (with headers) and I want G1 downwards to only list data that matches my criteria. Criteria being:

If Column D contains a specific value ie $F$1, then return the whole line/certain cells within that line.

So if D3 contained the contents of $F$1, then the A3->G3/or specific cells in that row are returned in G1 across. If the next row was 5, then it would do the same but in to G2 across. So essentially its creating a mini table from the master table.

Any help would be appreciated. I have tried Vlookup/Hlookup, and Index, but am obviously doing it wrong.

Kind regards

Adrian

RE: Lookup Function

Hi Adrian,

Thank you for the forum question.

I have attached a workbook with VBA code which can do what you want. Well it is not exactly what you want. I hope it is OK. To get it to work I had to create the new table from column H instead of column G.

I hope this can help you.



Kind regards

Jens Bonde
Microsoft Office Specialist Trainer

Tel: 0207 987 3777
Best STL - https://www.stl-training.co.uk
98%+ recommend us

London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector

Attached files...

copy to new dest.xlsm

RE: Lookup Function

Hi Jens

Thank you so much for your help, its really appreciated. That has ended hours of me searching/trying to figure out the issue over last 2 days.

Kind regards

Adrian

RE: Lookup Function

Hi Adrian.

I am happy to help.


Kind regards

Jens Bonde
Microsoft Office Specialist Trainer

Tel: 0207 987 3777
Best STL - https://www.stl-training.co.uk
98%+ recommend us

London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector

RE: Lookup Function

Hi Jens

Again, thanks for help with this. I have adapted the macro and data to fit what I have, but essentially its very similiar. However, my questions are:

1. If the data looked similiar to the below, how could I create a running total formula for the vba output. The trick is that the Running Total differs because numbers associated with the dates drop off and can cross months ie

Start End Total Cum Total
01/07/2015 31/07/2015 100 100
03/07/2015 10/07/2015 300 400
08/07/2015 15/07/2015 100 500
11/07/2015 12/07/2015 200 400
16/07/2015 25/07/2015 100 200

2. What if the data is on 1 worksheet, yet I want the results to populate in to another worksheet. I am experiencing the following error, when I try to amend this:

'Run-time error 110041: Selected method of Range class failed.' **This relates to dRange.Select**

Sub TestH078()

Dim dRange As Range
Dim rngCell As Range
Dim lRow As Long
Dim lBlank As Long


Set dRange = Worksheets("MTS DATA").Range("a1").CurrentRegion.Columns("I")
dRange.Select

For Each rngCell In Selection
iRow = iRow + 1
If rngCell.Text = Range("A1") Then
Range("A" & iRow, "L" & iRow).Copy
lBlank = Worksheets("WIP").Range("C1").CurrentRegion.Rows.Count + 1

Range("C" & lBlank).Select
ActiveSheet.Paste
End If
Next rngCell

Application.CutCopyMode = False




End Sub

Any help would be much appreciated, thank you.

Adrian

RE: Lookup Function

Hi Adrian,

I have not been in the office for some days so I am sorry that you had to wait for an answer.

Please find attached workbook with running sum.

About the error please click in A1 and press down CTRL SHIFT * (CTRL SHIFT 8). Does this selection include column I ??



Kind regards

Jens Bonde
Microsoft Office Specialist Trainer

Tel: 0207 987 3777
Best STL - https://www.stl-training.co.uk
98%+ recommend us

London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector

Attached files...

runningtotal.xlsm

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

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.17 secs.