Is it possible to Populate a listbox with a non-contiguous named range? - vba

I have a single column list box, which I want populated by table names that are on one worksheet. I've Ctrl clicked all the names and named them, however when I enter the range name into the properties table of the userform, they don't show up. What am I doing wrongly?
I would also state that I want to avoid creating a separate list on another worksheet.
What is intriguing is the fact that when you copy non contiguous data and paste it, it pastes contiguously. How does excel do this? I've recorded the macro and it's just 'activesheet.paste'. Can you paste into an array? ...to then use the array as the list, without having to create another list?

you can do this:
arrayname = rangename.value 'set named range to array
sheet1.listbox1.list = arrayname 'set array to listbox values

Related

I would like to match the data of two columns in two different excel workbook

I have two excel WORKBOOK (WB)
In excel WB 1, I have column for student IDs and Advisor name.
In excel WB 2, I have IDs to be matched to WB 1 IDs if the Advisor name is "John" to show "TRUE' in a column in WB2.
Can you pls tell me what are the formulas to try AND EXPLAIN THE COMPONENTS OF THE FORMULA?
aTTACHED IS THE SCREENSHOT OF DATA.
pLEASE NOTE ITS IN DIFFERENT EXCEL WORKBOOKS NOT SHEETS.
Taking your provided formula I will run you through the minor change that will make this work:
=IF(ISNUMBER(MATCH(C7:C17&"John",'[wORKBOOK1 NAME]SHEET1'!$A$2:$A$13&'[wORKBOOK1 NAME]SHEET1'!$B$2:$B$13,0)),"True","False")
This of course is assuming that the Forenames are in $B$2:$B$13...
What this is doing is simply forming a string value of the ID with the Forname stuck onto the back of it. MATCH will reference an array of values that it creates from the criteria within itself - the ID with the Forename.
The match formula will work in the same way, returning an integer representing the index location within the array when the match is found.
I will point out that the formula does not accept an array for the first argument, so currently only the first cell is being searched... You will want to update the formula and perhaps have this as a column checking each individual ID:
=IF(ISNUMBER(MATCH(C7&"John",'[wORKBOOK1 NAME]SHEET1'!$A$2:$A$13&'[wORKBOOK1 NAME]SHEET1'!$B$2:$B$13,0)),"True","False")
If you wanted this as just one formula it gets a bit more complicated as you must form an array using an if statement and Evaluate against that array:
=IF(ISNUMBER(MATCH(1,IF(C7:C17&"John"='[wORKBOOK1 NAME]SHEET1'!$A$2:$A$13&'[wORKBOOK1 NAME]SHEET1'!$B$2:$B$13,1,0),0)),"True","False")
This must be entered as an array formula (While still in the formula bar hit Ctrl + Shift + Enter)
The if statement will check for the match and build a new binary array (1 for a match and 0 for no match), the MATCH formula then is simply checking if a match is found in that new array by searching for 1.

VBA for isblank to enter values into form

I am new to scripting VBA from scratch. I have been using formulas to complete the task, but it is requested that I use a VBA to eliminate the excess spacing needed for my formulas to work properly. I have multiple worksheets that I want to the data from to populate my form(s). If column A represents the selection of the item by entering the quantity or no charge(NC). example of my worksheet is:
I have the selected data in if isblank = false formulas that combines the selected line into one string for the order form. Then I use the left, right, and mid formulas to separate the string into the columns needed for my check list form.
What I want to do is eliminate using the one text string, and use the if isblank = false to populate my check list form.

Lookup function in multiple sheets data

I have multiple sheets of data and I want to make it in one sheet (All of them are in the same workbook). Link to the excel file.
I tried to use Hlookup function in excel file, something like below:
=HLOOKUP("University",Sheet1!$A$1:$G$2, 2, FALSE).
But, since I have more than 100 sheets of data, I want to find a way to drag the function and auto generate the function below the 2nd row. I have tried to use indirect function by setting a reference column in front as below but cannot deal with it.
=HLOOKUP("University", 'INDIRECT(A3)'!$A$1:$G$2, 2, FALSE)
My next option is VB code. But, I am new to VB. Anybody can help on it?
Place your individual sheet names in column H of the Summary sheet and the row number in column I (as helper columns) and write this formula in cell A2 of the summary sheet.
=IFERROR(HLOOKUP(A$1,INDIRECT($H2&"!A1:G"&$I2),$I2,0),)
and drag to column F and down for as many sheet rows combos you have. I used 10 rows but you can obviously make it longer or shorter as neeed.
When you are done you can filter on 0 in column A and remove any lines with no data.
If your sheet names have spaces in them, you'll need to adjust the INDIRECT formula to this:
INDIRECT("'"&$H2&"'!A1:G"&$I2)
best way would be "defined names" + INDIRECT + HLOOKUP (or LOOKUP) like:
defined names
name: SList
formula: =MID(TRANSPOSE(GET.WORKBOOK(1))&T(NOW()),FIND("]",TRANSPOSE(GET.WORKBOOK(1))&T(NOW()))+1,255)
formula in cells: (this in A2 then simply autofill to G2 and thenn everything down) (you'll get a row with 0's between the sheets, which can be filtered out or deleted later (copy/paste values))
=IFERROR(HLOOKUP(A$1,INDIRECT("'"&INDEX(SList,COUNTIF($A$1:$A1,0)+2)&"'!$A:$G"),$H2,0),"")
Set H2 to 2 and for H3: (autofill down from H3)
=MAX(($H2+1)*($A2>0),2)
works perfectly for me LINK
No manual typing of sheetnames or something like that (only Column H:H as helper). Youll get rows's with 0's every time a new sheet is selected which can be filtered out. (or if you copy/paste values also can be deleted)
the +2 at ...st,COUNTIF($A$1:$A1,0)+2)&... simply tells to start with sheet 2 (if summary is the first). You may change it to +1 if you want to lookup starting with the first sheet.
Assuming you already have all 100+ sheet names typed out in column A, this will work whether or not you have spaces in the sheet names:
=HLOOKUP("University", OFFSET(INDIRECT(ADDRESS(1,1,1,1,A2)),0,0,2,7),2,FALSE)

with a VBA userform, how do you populate a combobox with a different text and value?

I am trying to populate a VBA userform combobox with a named range, and I want the text value to display in the combobox for the user to select, but the value I want returned is the cell reference to the initial named range. That way it would point back to the named range, and if I change that text, it would automatically update all the references I have on the sheet that were entered by the form.
Right now I can get the named range to populate the combobox by iterating through the range, and using an .AddItem to give it the textual value, but then it just dumps that textual value into my spreadsheet, when instead I would like it to have the cell reference from the range that populated it.
The easiest way to do this is to create an Array(X,2) X being the number of items in the array. Then you put the String you want to display in Array(1,1) and the data you want in Array(1,2) then simply populate the combo box like normal. When you and use the array to reference which item they choose. They choose item 8, you know it is Array(8,2) If you need more help please post some code.
So, after more research it would seem that I am unable to directly accomplish what I want with the combobox. I ended up just looping through the range to fill the combobox with the textual values, and then when I submit the form, I looped through the same range of values, checked it if the submitted value matches one from the range of values, and if it does, then return the .Address instead of the .Value, and that gave me the cell reference I was looking for. Too bad the combobox doesn't work more like a real html select menu, it would have made my life a little easier, but in the end I was able to make it work, it just isn't as clean as I would have liked.

Take Textbox input and move to a specific cell.

I'm writing a macro to pull various data from an Excel sheet and put it in a more usable order. A problem I've run into is that one section of the data I want is contained in a textbox. I'd like to pull the data out of the textbox and have it all pasted into a cell, A100.
The textbox is always called ActivityA.
try this
Cells(100, 1) = ActiveSheet.Shapes("NameOfYourTextBox").DrawingObject.Text