Create a list from Table - vba

I managed to enter data to a database via a form;
actually works like a charm.
Now, what I need, is a lookup function (preferably not a form), with which I can search a table on another worksheet.
Let's say, I have an edit field or a cell, in which I enter a term which shall be looked for in a certain column on the table in another worksheet.
I would like to get a list of all entries which contain the word and the value from another cell (an ID).
Example:
Search term: Tom
Table:
Tim | 2
Tom | 3
Tommy | 5
The List should Show Tom and Tommy and their respective IDs,
but everything I tried didn't turn out as intended (mostly didn't work at all)...

Related

How to map two column using another column data

I have Five columns.
E.g.
Column1: Name
Column2: surname
Column3: mapping
Column4: Mapped data
Columns contain data like
Name Surname Mapping Name1 Surname1
1 ABC 1 AAAA 3 ABC QQQQ
2 XYZ 2 XXXX 1 XYZ AAAA
3 OPQ 3 QQQQ 4 OPQ RRRR
4 RST 4 RRRR 2 RST XXXX
Now my aim is to map name column to surname by using mapping column and result should be stored at Name1 and Surname1 column. I have more data in Name and Surname column, by writing number in Mapping column it will automatically map the surname to Name (the choice is given to user for entering number in mapped column then map the data accordingly) and result should be copied in Name1 and Surname1.
I am not getting any idea to achieve this using VBA. coding Plz help me.....
Amar, there are certainly plenty of ways to go about this using Excel's built in functions, however, since you asked about a VBA solution, here you go:
Function Map(n)
Map = Cells(n + 1, 2)
End Function
Placing the above code into the VBA editor of your project will allow you to use this custom function in the same way you would any of Excel's builtin functions. That is, entering =Map(C3) into any cell should give you the result you're after (where C3 is the cell containing your mapping number). The function works by returning the data in [row n (defined in your mapping column) +1 (to account for the header row); column 2 (the column containing your surname)]. The data in column "Name1" will always be the same as that in column "Name" (so it seems). So the function in your "Name1" column would simply be =A2
If this does not solve your problem, or you need further guidance, please let me know.
Supplement
#Amar, the comment by #freakfeuer is spot on. VBA is really overkill for something as simple as this and, as he points out, portability and security are both significant drawbacks. Offset is a fine alternative.

How to display concatenated value in MS Access Combobox

I'm trying to fill the combobox with values from a concatenated field in a MS Access query. The embedded image is what is currently shown in the drop down box and what is shown in the box when a value is selected.
The problem is that i do NOT want the values in the drop down box to show as if in columns, but rather as a concatenated string. So, instead of ... TAYLOR | AVICHAI ... it should be TAYLOR, AVICHAI. And additionally, when the value is selected, then instead of showing just TAYLOR it would show TAYLOR, AVICHAI.
I've tried every property I can think of and tried concatenating in the original table, the query and even in vba code AFTER just grabbing the two fields from the database.
Any help? Concatenated View
You need to concatenate the values together in your query and display that field in the combo box.
SELECT peopleID, lastName & ", " & firstName AS name FROM tblPeople
And then in your the format tab of your combobox set:
column count to 2
column widths to 0";1"
This will cause only your column with a width (the combined names) to be displayed in the drop down and when selected.
The documentation says: "In a combo box, the first visible column is displayed in the text box portion of the control."
More precisely, the value shown is the value of the first column with a non-zero width.
Thus, to achieve your goal, modify your query so that it returns the following:
Taylor, Avichai | Taylor | Avichai
Raines, Patricia | Raines | Patricia
...
Then, in the combox box properties, set
the number of columns to 3 and
the column widths such that the first column is very small (but not zero).

Excel 2013 VLOOKUP() based on multiple criteria, retrieving multiple rows

I have an issue that can (I believe) be solved by just excel, and may won't require VBA (I could be wrong). I believe it can be solved by nested functions but the formula I've tried has not worked.
Here's my data:
Name Report # Name
Mark Doe ReportXXX Mark Doe
Connie Doe ReportYYY Connie Doe
Debbie Doe REPORTYYY Debbie Doe
Valerie Doe FSMVALTR1 Valerie Doe
Jeff Doe FSMVALTR1 Jeff Doe
Andy Doe RAZXYBCA1 Andy Doe
Ryan Doe RAZXYBCA1 Ryan Doe
Andy Doe RAZ111111 Jill Doe
Ryan Doe RAZ222112 Amanda Doe
This list goes on for about ~4000 rows in the first NAME and REPORT # columns. In the second NAME column I have ~160 rows.
The second name column identifies all the users who actually use the report, with no duplicates. The two name and report # columns have many duplicates, since users have access to multiple reports, and many of them are the same report used for different purposes. Since the second NAME column has so few rows, the names don't match up all the way through, which can be observed near the bottom of both the NAME columns.
What I need to do is have a VLOOKUP that identifies the name in both of the columns and then returns the report number that each individual has access to across rows (horizontally), not down the columns. It also needs to I.D. numerous reports since individuals have access to anywhere from 1-15 reports, starting at the second and so on after the previous has been extracted.
Ideally it would look something like this:
Name Report # Name ex column ex column ex column
Mark Doe ReportXXX Mark Doe ReportXXX ReportAAA ReportB
I didn't list the other reports "Mark Doe" has access to and these would be somewhere down the long list of ~4000, along with his name repeated multiple times in the first NAME column, but the second "unique" name column would be where it is returning the reports to, across rows.
I made a method that uses additional three columns and it worked for me.
I used the data you provided above.
Add three columns to the left.
in A2 enter =COUNTIFS($D$2:$D2,D2,$E$2:$E2,E2).
in B2 enter =SUMIFS($A$2:$A2,$A$2:$A2,1,$D$2:D2,D2).
in C2 enter =D2&B2.
Now copy those cells to all your 4000 rows.
Now next to the second name column add column headers numbered from 1 to as many reports you think can be the max one user can have (you said 15).
Now enter this vlookup in F2 =IFERROR(VLOOKUP($F2&G$1, your table array starting from column C as absolute/fixed ,3,FALSE),"") in my case it was =IFERROR(VLOOKUP($F2&G$1,$C$2:$E$11,3,FALSE),"").
Copy the formula accross all columns with number headers and down all rows that have names in second name column (160).
your sheet shuld look something like this image
All the best let me know if it worked for you.
Have you explored the option of using a Pivot Table?
The output would look like this:
With the Pivot Table setup like this:
This method would make for a cleaner view, as your current method looks to repeat ~4,000 times (once for each report & name combo). Hopefully this works for what you need.

Display only two fields from Access table

New to Access here... I asked a similar question the other day, but have a new twist for a different form I am creating.
Say I have a table (tblNamesAndValues) that looks like this:
Name Value
---- ----
Mary 100
Carrie 500
Terri 999
Gerrie 749
I have created a form that displays all four names and values.
My question is this: how can you make the form display only the names Mary and Terri and their values, and have the values in updateable textboxes? On top of that, is there any way to only display those two, and not the blanks underneath that allow new entries?
Thanks in advance...
You can filter the form or use a query instead of the table as table source:
select * from tblNamesAndValues where name = "Mary" or name = "Terry"
For disabling the blank line, just set the AllowAdditions property of the form to false.

Merge rows with same Column A

I am new to VBA and from what I have seen it will be the best way to go about doing what I want to do. I have an excel spreadsheet with Column A being the name of a company and Column B being the state which it is in. Since companies are in multiple states there are repeated company names, I would like to make it so that Column B has a list of the states so that Column A does not repeat. I know that similar questions have been asked but like I said I am new to this and have never used VBA before so some of the code without an explanation is not all that helpful.
For example I would like to go from:
Company 1 | MI
Company 1 | IA
Company 1 | MD
Company 2 | MI
Company 2 | OH
To this:
Company 1 | MI, IA, MD
Company 2 | MI, OH
Any help would be greatly appreciated or suggestions of ways other than VBA would be appreciated.
I suggest you put both columns in the ROWS area of a PivotTable and ensure that has no subtotals and is in tabular format.
You may not need vba at all. One way to get the results you want is to put the following equation in Column C (assuming Company is in A and States are in B):
"=IF(A2<>A1,A2,"")"
Without the outside quotes. Then just drag the formula to fill to the bottom of the data. Also, if you use this formula, start the data on A2, as the formula will look at the cell above.
The D column is simply =B2.
The VBA code will follow this logic as well, if you still want to use VBA.