This seems like a very simple problem but I just cannot find documentation for it, on MSDN.
How can I create a UserForm in Excel that will let user select many items?
Example(assuming that this will be done using listbox, otherwise better solution will be used):
_______
|item1 | <- pick this
|item2 |
|item3 | <- ,and pick this
|item4 |
|______|
me.listbox.multiselect=1 lets user select multiple lines.
further you need to loop through your list for i=0 to me.listbox.listcount-1 ,
and to check if item is selected if me.listbox.selected(i) = true then.... do stuff
note : a list starts with 0 (like in my FOR loop), so your first item is called me.listbox.list (0).value.
info on the selected method : http://msdn.microsoft.com/en-us/library/office/gg251644%28v=office.15%29.aspx
Related
I am able to enter to the operation in SAP GUI via VBA but I am unable to find how to select or copy the value of these fields.
While recording the script via SAP GUI, copying the fields into the clipboard won't appear in the script as an action.
Any help or reference is highly appreciated.
Please find code and screenshot below (screen of type "ABAP List").
Sub XXXX()
Call SAPConnections
Session.FindById("wnd[0]/tbar[0]/okcd").Text = "Operation"
Session.FindById("wnd[0]").SendVKey 0
Session.FindById("wnd[0]/usr/ctxtP_MATRL").Text = "PartNumber"
Session.FindById("wnd[0]").SendVKey 8
Session.FindById("wnd[0]/tbar[1]/btn[1]").Press
The screen you are showing is named an "ABAP List".
It contains labels and text fields, they belong to the property Children of the GuiUserArea object, and their IDs are made of prefix lbl or txt followed by the column and row numbers. The respective SAP GUI Scripting objects are GuiLabel and GuiTextField, for example:
label at column 0 (first column) row 12 (object GuiLabel):
/app/con[0]/ses[0]/wnd[0]/usr/lbl[0,12]
text field at column 22 row 12 (object GuiTextField):
/app/con[0]/ses[0]/wnd[0]/usr/txt[22,12]
checkbox at column 0 row 0 (first row) (object GuiCheckBox):
/app/con[0]/ses[0]/wnd[0]/usr/chk[0,0]`
If you want to know all the fields which are in the ABAP list, you must loop at the property Children of the GuiUserArea object.
EDIT: checkbox added in the list above. I think we now have all the possible types of fields for an ABAP List (I guess other simple graphical elements objects like GuiButton, GuiComboBox, GuiCTextField, GuiRadioButton, are not possible).
EDIT: see this more detailed answer with a script to loop at all ABAP List fields and example with a screen and corresponding property values.
I am a complete VBA beginner and this is the first time I have had to deal with VBA. My project is simple- a user form which heavily relies on dependent drop down lists. I watched a ton of videos and wrote (more like copy-pasted) code which actually works just fine. My issue is that I need to edit part of my code to add a feature which I have trouble finding a video on (trial and error editing only took me this far).
In it's current state, my form has two dropdown lists drawing information from a sheet where data is arranged in columns as follows:
ITEM ID | ITEM | CATEGORY
The user picks a category and then the item list if filtered based on the previous selection. I now need to rearrange those columns are add another one, making it the 1st tier selection as follows:
LOCATION | CATEGORY | ITEM ID | ITEM
Just rearranging the columns alone breaks my code. On top of that I need to add the Location combobox, which would filter the Categories, which in turn filter the Items.
This is the code which handles the CATEGORY and ITEM list:
Private Sub cmbEquipCategory_Change()
Dim sh As Worksheet
Dim lastBlankRow As Long
Me.cmbEquipment.Clear
Set sh = Sheets("Equipment_List")
lastBlankRow = sh.Cells(Rows.Count, 3).End(xlUp).Row
For i = 2 To lastBlankRow
If sh.Cells(i, 3) = Me.cmbEquipCategory.value Then
Me.cmbEquipment.AddItem sh.Cells(i, 2)
End If
Next i
End Sub
It is my impression that I need to alter this code to draw data from columns 2 and 4 (it currently does so from 3 and 2) and write another almost identical block of code which handles LOCATION and CATEGORY. Any advice, resources or help would be greatly appreciated. Thanks!
The way I do this is to used named ranges. So selecting your ITEM ID would lead to one of several ITEM ranges (I name them according to the ITEM ID options) which would lead to one of several CATEGORY ranges (I name these according to the ITEM options). The more options you have the more ranges you need. Named ranges aren't broken by adding in columns.
I have an Excel-file with 2 tabs:
Tab1
ActorID | ActorName
--------------------
4321 | ActorName1
4322 | ActorName2
4323 | ActorName3
4324 | ActorName4
In the second tab I want to put in the name of the actor and see if it's in the array
So I used this formula: =(Tab1!A1:A10="ActorName1"), but I get FALSE. When I use the same formula in the first tab (=(A1:A10="ActorName1")) I get TRUE.
I don't understand why I get FALSE if the formula is used in another tab :/
The formula works on the tab only if the name you are searching is the first. You are trying to compare an array to a single item, Excel will only look at the first.
To search a range of names use MATCH(). To return TRUE/FALSE wrap it in ISNUMBER(), as MATCH will return a number if found or an error if not found.
=ISNUMBER(MATCH("ActorName1",Tab1!A1:A10,0))
So say I have a table x by y entries.
X is far too great, or changes often enough, that making X additional tables/lists/named ranges is absurd.
However, I need to make a drop-down list of some of y.
Specifically:
Name | A | B | C | ..
Yannis| 20 |Yellow| Green| ..
Mirrah| 400 |Purple|Yellow| ..
.
.
.
I need a drop-down select of Name to change the options in a different drop-down list, which is based off of B & C.
Normally you can do this with either a Filter or INDIRECT(). However, it is beyond unreasonable to create a unique table, or name define, for each entry in X.
It is possible to create a table with all the possible entries for B & C, if there was a way to filter a named define for a list based off of the first table (using vlookup(), most likely)
In layman's terms: I need list 1 to filter list 2 where list 1 is either enormous or subject to constant change.
Gah, so this:
=INDIRECT("'InfoDump'!" & ADDRESS(MATCH(C5,PkmList,0)+25,10))
put into the data validation list works, however it's only one entry, and I need 3.
simply adding commas and copies causes error messages.
The one entry that this supplies is correctly referenced (dynamically) from the table without any need for more tables/namedRanges.
C5 is where the first list is
PkmList is the NamedRange for the first column of the Table
+25 'cause the table starts at A25 (column title)
10 referencing the first of 3 columns I need in the second list.
Okay!
After some experimentation, this accomplishes what I was looking for:
=INDIRECT("'InfoDump'!" & (ADDRESS(MATCH(C5,PkmList,0)+25,10)) & ":" & ((ADDRESS(MATCH(C5,PkmList,0)+25,12))))
or, in some different terms:
=INDIRECT("'sheetName'!" & (ADDRESS(MATCH(DropDownOne,DropDownOneCriteria,0)+(AdjustRow),(AdjustColumn))) & ":" & ((ADDRESS(MATCH(DropDownOne,DropDownOneCriteria,0)+(AdjustRow),(AdjustColumn)))))
Data validation hates logic.
-
In the most basic sense:
Match(a,b,c) gets the location of 'a' in 'b' (c is the same as vlookup's exact match option)
Address(row,column) gets the "j26" address, you can (as I did) adjust from where you found the match. (in my case, 25 down 'casue the table actually started at A25, but the list started at '1'; then 10 - 12 across for the 3 options I needed to list)
indirect(txt) turns this into a list. more or less. use "'sheetName'!" for referencing a different sheet.
-
So in the end this gives you a "=A2:A4" in the Data validation bar, based on another list. Same as using the popular work around that is the fruit vegetable cabbage example, but this doesn't require you to make multiple named ranges. (Which means it works for a single large changing table).
Is there a method whereby columns in Excel (2003, 2007 and/or 2010) can be automatically shown (un-hidden) when the column to the left contains data?
Something like this:
IF column to the left contains data
THEN show column
+-----+-----+
| C | C | //If column1 contains data
| O | O | //Then reveal/show (unhide) column2
| L | L |
| U | U |
| M | M |
| N | N |
| 1 | 2 |
+-----+-----+
I'm guessing that VB code is required but am unsure as to what this would be.
Further to this, is there a way to automatically show the column going by the date (first day of each month)? This is a little more complicated. For example:
FOR all dates
IF system date = year(month.day1) //If it is the first day of a new month
THEN show column(month) //Then show the corresponding column for that month
ENDIF
ENDFOR
i.e. IF system date = 01/09/2012
THEN show column(September)
Is this possible?
Thank you.
Correct, you need VBA to achieve that. Use the Worksheet_Change event which fires whenever something changes. Then, use one of the various methods to determine if a column is not empty (http://ewbi.blogs.com/develops/2006/03/determine_if_a_.html, or just google). Alternatively, if this is to slow because if fires almost all the time, you could use the Worksheet_Activate() event (an overview of all Excel events can be found here).
If your column 7 contains data, you can unhide column 8 using MyWorksheet.Columns("8:8").Hidden = False.
Your second problem can be solved in a similar way. In the Worksheet_Activate(), check if today is the first day in a month using Day(Date) = 1 (I guess it needs to take into account that the user may not be using Excel this day, so the code should be a little more complex) and show that column using MyWorksheet.Columns("12:12").Hidden = False (or whichever it is) for December 1st.
All this code assumes that the columns are already there, just hidden.