![]() |
#1
|
|||
|
|||
![]()
Hello everybody. I have attached a test workbook where you can easily see what the problem is: in ULD I have some data in columns A, B, C and D. In Loadsheet I recall the data by the use of Vlookup. The problem is that I get doubles (when I input the same weight I get twice the same ULD). Is it possible to get some sort of userform that has the data of all the columns for those columns that have the same weight for me to choose (in the test case an userform with 2300 - 12345 - q7 gyd and 2300 - 55555 - ord). Of course if one of the double has already been chosen the choice will not be necessary anymore and the values that have not yet been used should be automatically be used.
I hope my request make some kind of sense Thank you all for any help |
#2
|
||||
|
||||
![]()
For matching with repeated data, see:
http://windowssecrets.com/forums/sho...l=1#post734296 http://www.techsupportforum.com/foru...ml#post2567119
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
![]()
Here is a custom function that may be of assistance. Note that although I have done a little bit of testing, it has not been tested extensively, so please review the code and test that the function works as expected before depending on it!
Code:
Public Function vlookupx(lookup_value As Variant, table_array As Range, col_index_num As Integer, range_lookup As Boolean, occurrences As Integer) As Variant 'Declare variables Dim i, count As Integer Dim ivalue As Variant On Error Resume Next 'Protect against erroneous inputs If col_index_num > table_array.Columns.count Then vlookupx = CVErr(xlErrRef) Exit Function End If If occurrences < 1 Then vlookupx = CVErr(xlErrNA) Exit Function End If If range_lookup = True And lookup_value < table_array.Cells(1, 1).value Then vlookupx = CVErr(xlErrNA) Exit Function End If 'If range_lookup = true then assume first column is sorted ascending 'Finds largest value that is smaller than lookup_value if lookup_value not found If range_lookup = True Then count = 0 For i = 1 To table_array.Rows.count ivalue = table_array.Cells(i, 1).value If ivalue > lookup_value Then vlookupx = table_array.Cells(i - 1, col_index_num).value Exit Function ElseIf ivalue = lookup_value Then count = count + 1 If count = occurrences Then vlookupx = table_array.Cells(i, col_index_num).value Exit Function End If End If Next i vlookupx = table_array.Cells(table_array.Rows.count, col_index_num).value Exit Function 'If range_lookup = false then look for exact matches Else count = 0 For i = 1 To table_array.Rows.count ivalue = table_array.Cells(i, 1).value If ivalue = lookup_value Then count = count + 1 If count = occurrences Then vlookupx = table_array.Cells(i, col_index_num).value Exit Function End If End If Next i vlookupx = CVErr(xlErrNA) Exit Function End If vlookupx = CVErr(xlErrNA) End Function This function could be used in your example spreadsheet as follows =vlookupx(B1,ULD!$A:$D,2,0,COUNTIF($A1:B1,B1)) Hope that helps. |
#4
|
|||
|
|||
![]()
hello Peter, I have copied and pasted the function in VBA under Loadsheet. I then copied the formula for both cells A and B but in both cases I get #NAME as result. What do I do wrong?
|
#5
|
|||
|
|||
![]()
You will need to insert the custom function into your workbook as follows
|
#6
|
|||
|
|||
![]()
Peter, I have done as you told me and it works. I have a last question that concerns this matter: what if I have to select multiple ranges in Countif? in my real sheets I have ranges A13:AZ13 and J17:AX17 and G26:S26 and AE26:AN26. I know that countif cannot handle multiple ranges and I have tried with +countif but it doesn't work
|
#7
|
|||
|
|||
![]()
I would have thought that adding multiple COUNTIF functions together should work. Would you be able to post a copy of your formula?
You could also try the COUNTIFS function, which is probably a more elegant solution than using multiple COUNTIF functions. http://office.microsoft.com/en-us/ex...010047494.aspx |
#8
|
|||
|
|||
![]()
hi there Peter, here you have the formula as I use it
=vlookupx(A13;ULD!$A:$D;2;0;COUNTIFS($A13:$BB13;A1 3);(J17:AY17;A13);(G26:U26;A13);(AE26:AP26;A13)) |
#9
|
|||
|
|||
![]()
Try this
=vlookupx(A1,$A:$D,2,0,COUNTIFS($A13:$BB13,A13,J17 :AY17,A13,G26:U26,A13,AE26:AP26,A13)) |
#10
|
|||
|
|||
![]()
hello Peter, I have tried the formula as you passed it but I still get the #VALUE error. Why is that that in the formula you refer to A1? and... why don't we refer to the ULD! sheet anymore? I ask you these questions because I would like to learn from this.
|
#11
|
|||
|
|||
![]()
My apologies, I made some changes to the cell references when I was trying to get the formula working and I forgot to change them back.
=vlookupx(A13,ULD!$A:$D,2,0,COUNTIFS($A13:$BB13,A1 3,J17:AY17,A13,G26:U26,A13,AE26:AP26,A13)) Note that your original formula was logically correct - it just had a few syntax errors. In particular the parameters of the two functions must be separated by commas ',' and contained within a set of ()'s so the formula needs to take this form... =vlookupx( <cell containing lookup value> , <range of cells to lookup in> , <column number to look up> , <0 or 1> , COUNTIFS( <range of cells 1> , <criteria for range of cells 1> , <range of cells 2> , <criteria for range of cells 2> , ... )) |
#12
|
|||
|
|||
![]()
Hello Peter, what if the separator I use is ;?
|
#13
|
|||
|
|||
![]()
You will need to replace all of the ,'s in the formula that I posted earlier with ;'s and it should work.
|
#14
|
|||
|
|||
![]()
hello Peter, sorry for the late reply but I have been away... all works fine, thank you very very much for your help
|
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
ExecAssist | Mail Merge | 1 | 02-27-2012 04:06 PM |
Table doubles up in MS Word 2010 but not in 2003 | seguinju | Word | 3 | 02-24-2012 11:07 PM |
![]() |
b0x4it | Word | 4 | 06-14-2011 10:01 PM |
Is it possible for Excel print consistently with any printer? avoid awkward page brea | William C | Excel | 1 | 12-21-2010 01:40 PM |
How do I avoid Hourglass using API Function? | sauerj | Word | 1 | 11-10-2010 06:53 AM |