Trying to find a specific row with a name in that row in vba excel - vba

I have a spreadsheet with column A having a list of names in it. I then have a userform that uses those names to make an attendance report. When The enter button is pressed it takes the name and finds what row that name is at then finds the next empty cell in that row and puts the info in that cell. My question is how do I search for that name and get the row that is associated with that name? I have done some research but what I have found I didn't quite understand how they are being implemented. I thought about vlookup but wasn't sure if that would give me the row number?

You could use a quick Match():
=Match("MyName",$A$1:$A$10000)
That should return the row number. Note this is relative. If the name is in A1, the above will return 1.
If you do this, however, =match("myName",A2:A100), and the name is in A2, it will also return 1.
Edit: Sorry, for VBA this should work worksheetfunction.Match(neName.Value,Range("A1:A100"),0)

Related

Auto populating rows from another sheet conditional to a specific cell value

Hello i am trying to autopopulate rows from another sheet if a specific value if found in a specific cell. So far, i managed to do it manually by adding this line in Sheet #2 for each cell.
=IF(OR('Le 2250'!$C48="Nouveau locataire",'Le 2250'!$C48="Décès", 'Le 2250'!$C48="Retention"), 'Le 2250'!$B48,"")
I am trying to create a vba script that will generate each column in Sheet#2, and that will dynamically update regarding if i add a row in Sheet 1 or delete it.
Sheet1 is:
Sheet2 is:
Your help is appreciated
What your looking for is the INDIRECT function
As an example:
=CELL("contents",INDIRECT("Sheet1!B5"))
This always pick up the value in Sheet1 Cell B5, regardless of changes in Sheet1.
For more information: Excel INDIRECT Function
Edit: To directly answer the question with INDIRECT.
=IF(OR(INDIRECT("'Le 2250'!C48")="Nouveau locataire",INDIRECT("'Le 2250'!C48")="Décès"),CELL("contents",INDIRECT("'Le 2250'!B48")),"")

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.

Excel 2016: IF function using position of cell relative to another cell

I'm trying to use IF to return a value that depends on the position of one cell relative to another in the same column.
Spreadsheet Example
If you click the above image, you'll see a number of columns with the possible values of "No," "Yes," "Yes>No," and "No>Yes."
The equation will go in the "Category of Change," row, one equation for each column. If the "Yes>No," is lower in the column than the "No>Yes," I want to return "Less Frequently," and if the opposite is true, I want to return "More Frequently" ("Same," if there is no "Yes>No," or "No>Yes").
I've tried using ARRAY and INDEX functions, but I'm not sure how to get Excel to "look" for each of those values, and then compare their ranking in the column.
Thank you in advance for your help!
MATCH will return the relative row number. This assumes the first column of data is in E2:E8.
=IFERROR(IF(MATCH("Yes>No",E2:E8,0)>MATCH("No>Yes",E2:E8,0),"Less Frequently","More Frequently"),"Same")
It is looking for exact matches, so if you have typos, it will always default to Same. If only one is found then it will still produce Same
You would put int he first cell and copy/drag over, the references will change automatically.

get multiple column names (header) in table associated with particular value in to a cell

i need to get multiple column names (header) in table associated with particular value in to a cell
as i explained, i need to get the heading names corresponding to value "n" to column E.
i used the formula
=INDEX((A$1:D$1),MATCH("n",A2:D2,0))
here. but it only give one column name.
i am open to vba scripts also. but i think it doesn't need vba. just improve the the above formula, may be. i tried and failed. any help. thank you guys
if you are really "open" to vba, I'll use one simple UDF like:
Function HeatherNames(rg As Range, rf As String) As String
For Each cell In rg
If cell = rf Then HeatherNames = HeatherNames & Cells(1, cell.Column).Value & "-"
Next cell
HeatherNames = Left(HeatherNames, Len(HeatherNames) - 1)
End Function
you can use it in the column E `=HeatherNames(A2:D2;"n") now you can select the arg.1 (range) and type (or referring to another cell) the arg.2
Assuming you have Excel 2010 or later, in E2:
=IF(COLUMNS($A:A)>COUNTIF($A2:$D2,"n"),"",INDEX($1:$1,AGGREGATE(15,6,COLUMN($A2:$D2)/($A2:$D2="n"),COLUMNS($A:A))))
Copy to the right and down as required.
It would actually be slightly more efficient (and certainly if your dataset in reality is quite large) to have the initial IF clause held within its own cell, such that it is calculated for each row only once, rather than for each instance of the formula within that row. So a better set-up would be, in E2:
=COUNTIF($A2:$D2,"n")
copied down. Then, in F2:
=IF(COLUMNS($A:A)>$E2,"",INDEX($1:$1,AGGREGATE(15,6,COLUMN($A2:$D2)/($A2:$D2="n"),COLUMNS($A:A))))
copied to the right and down again.
Regards

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)