I have a list with two items: HUN and EN, this is named as LIST. I also have two other cells named as HUN.L_LANG and EN.L_LANG, and I'd like to fill a cell dynamically based on the selected list item. So if the HUN is selected, then I'd like to fill the cell with the value of HUN.L_LANG, something like this: ="Value of LIST".L_LANG.
Is this possible? I haven't found any workaround. If it's not possible, how do you solve this task with excel formulas? Thanks!
EDIT:
I don't want to overwrite the LIST cell. So let's say LIST is in cell A1 and I'd like to fill B3 based on the selected list item either with EN.L_LANG or HUN.L_LANG.
Eventually I solved it with a vba function:
Function GetLabel(lang, name As String) As String
Dim label As String
label = lang & "." & name
GetLabel = Range(label).Value
End Function
And I use it like this: =GetLabel(LIST;"L_LANG")
Related
I have two lists in excel and each of them contains a column of text + another column with points assigned to it. It looks something like that:
As you can see both text and points can change.
Additionally, I would like to add more lists to it (marked C, D, etc.)
On another sheet, I would like to prepare a summary that calculates the sum of the points assigned to text. I will a summary list with text entries:
and I am looking for a formula which will give me sum of the points from all lists IF text from Summary cell matches any text from any list on previous sheet. The end results for these two lists will look like that:
I tried some SUMIF variations but never got what I wanted. Can someone help me find correct formula?
Here is a more general case.
Say Sheet1 has many arbitrary data sets between column A and column Z like:
First put the following User Defined Function in a standard module:
Public Function Gsum(rng As Range, patrn As String) As Long
Dim r As Range
Gsum = 0
For Each r In rng
If r.Text = patrn Then
Gsum = Gsum + r.Offset(0, 1)
End If
Next r
End Function
Put the data abc in Sheet2 cell B2 and in Sheet2 cell C2 enter:
=gsUM(Sheet1!A1:Z27,B2)
You have to take all the range, like that :
French Version = =SOMME.SI($A$2:$C$5;A8;$B$2:$D$5)
English Version = =Sumif($A$2:$C$5,A8,$B$2:$D$5)
Assuming your data is on sheet1 starting in A1 and the second sheet also starts in A1 on that sheet, put this in B2 and copy down:
=SUMIF(Sheet1!A:C,A2,Sheet1!B:D)
Try this and see if it works. I would test it but I am away from my desk at the moment.
Note, that this formula should be placed on a separate worksheet (just in case).
Sheet2!B2 = SUMPRODUCT(--(Sheet1!$A$1:$AZ$100=Sheet2!$A1), OFFSET(Sheet1!$A$1:$A$Z100,0,1))
Sheet1!A:AZ100 = The Range in which the data is contained
Sheet2!$A1 = The Cell that contains the criteria
You could of course use Friendly names for the ranges if you wish.
I am using a ComboBox (basically a drop-down list) in excel, and I would like to select a value from a range. Thing is, I have around 15 of those comboboxes that are linked to the same list, and I'd like to not have to modify the ranges for all of them if I add a value to my list.
Hence my idea of telling the dropdown to take the array given in cell A1 of my data sheet as input for the actual array...
I'm not sure I'm being clear so here's an example : my list is in the range A3:A25. I want to have "A3:A25" written in cell A1, and have my dropdown list take the value of A1 as the actual range, so that if I add an entry to the list I can change A1 to "A3:A26" and not have to change all of my lists.
Thanks in advance
Change the reference to:
=$A:$A
Be sure to tick Ignore blank.
Turns out I just selected my list and called it "List" (right click, -> define name), and defined the input range as "List".
Now if I add a value, I just have to redefine List.
Thanks
I'm using two cells with Data Validation - the first cell (E9) simply creates a drop down menu based on the range A2:A6, and the second cell (E10) validation uses the source INDIRECT(E9), which will always refer to one of five different named ranges.
When I have the named ranges fixed, (i.e A2:A250), the second drop down works, but I really need the ranges to be dynamic, so far I've been creating named ranges with the following "source" formula:
=OFFSET(LookupLists!$B$2,0,0,COUNTA(LookupLists!$B:$B),1)
With the other ranges being the exact same only in columns C-F.
When I write out this formula it highlights the correct area on the screen, but the drop down button in cell E10 is completely unresponsive, when the drop down list should show the exact area that's being highlighted.
As a note, the lists themselves are created using an array formula and some VBA code to create a sorted unique list based on another part of the spreadsheet, so I've been unable to use tables to create the ranges as some other websites have suggested.
INDIRECT doesn't work with dynamic ranges. Credit to these guys for the solution:
http://chandoo.org/forum/threads/passing-a-named-range-to-a-formula-with-indirect.5854/#post-32423
First, insert a module into you sheet and paste in the UDF:
Option Explicit
Function RetrieveRangeForName(psRange As String) As String
RetrieveRangeForName = Range(psRange).Address
End Function
Then you will need a helper cell, since I don't think UDFs work in the Data Validation dialog. In E11, enter =RetrieveRangeForName(E9).
Then in the Data Validation, set to List, you can enter: =INDIRECT(E11)
The reason it doesn't work as discussed here is that INDIRECT expects a string that it can evaluate to give a reference. However your named range is already a reference. Logically, the only way to use it in INDIRECT is to convert it into a string first which you can do with a UDF:-
Function GetAddress(Name As String) As String
Dim rng As Range, addr As String
Set rng = Worksheets("Sheet1").Range(Name)
addr = rng.Address
GetAddress = addr
End Function
Then use this to define a range called NewRange:-
=INDIRECT(GetAddress(Sheet1!$E$9))
Finally this can be used in the validation for E10 (Named Range ListB is defined as in the question, ListA etc. correspondingly for columns A to E).
I'm trying to figure clean up a spreadsheet - but I'm trying to avoid typing out a lot of hardcoded values that are referenced in formulas.
So right now, I have a function that takes a string
=FunctionThatWantsAString(A1,SomeOtherInputs)
In Cell A1 I have "SomeString"
Is there a way to easily replace the cell link "A1" in the formula with the string "SomeString"?
Thanks
The simple solution is to go to the Formulas ribbon > Defined Names > Name Manager > New [or simply select A1, and then click on the NameBox which says "A1" and type in "SomeString"]
This allows you to name a specified range. You can then refer to that name either within an excel worksheet or within VBA.
Edit for additional request
If you don't want A1 to have to hold the text "SomeString", you can actually use the name manager to create a name which refers to a string. ie: you can have the Name SomeString be equal to "asdf". Then, use ctrl+f to find and replace all instances of "A1," in your worksheet with "SomeString".
Alternatively , just use ctrl+f to find and replace "A1" with ""asdf"", and have your results hardcoded directly in all cells. Probably not recommended to do that though, for maintenance purposes.
If you are using a User Defined Function, you should check if that first parameter is a cell value, and if so, get the value.
Public Function test(st As Variant)
If TypeName(st) = "Range" Then
'get the value of the range or use the string passed in
'or if TypeName(st)="String"
End If
test = TypeName(st)
End Function
I'd like to setup my ComboBox values as a named array constant, where you go into the Name Manager and define a name and give it a value like:
={"A", "B", "C"}
I've found that ListFillRange will only take a Range so I can't assign to that.
Though it would work for a normal named range, like so:
myComboBox.ListFillRange = "MyList"
So how do you assign a Named Array Constant to fill a ComboBox?
I can't get your method to work for me but it's probably my setup?
If it were me attempting this I would either
Load the list programmatically item by item
or
2i) Assume arbitrarily "J" is the listfill range
2ii) Define a named range, say "COLJ" = =Sheet1!$J$2:INDEX($J$2:$J$65000,COUNTA($J$2:$J$65000))
2ii) Copy/Filter the items you want into J2:Jx
2ii) Assign the Listfillrange using VBA, myComboBox.ListFillRange = "COLJ"
After much searching I found this solution:
myComboBox.List() = Evaluate(ThisWorkbook.Names("MyList").RefersTo)