How to find a Particular value in particular range - vba

Here is a example of the sheets, in which I am trying to create a macro with vba.
In the first sheet, there is a value for NAME in D3, which is 25, it can change but number only.
In second sheet, there is table. Where b1,b2, b3, b4 till b13, are name(variable) values from 1 to 13(As in sheet d3, different value). In A1 to a13, there is serial no. from 1 to 13.
In third sheet, there is table.
Where b1,b2, b3, b4 till b13, are name(variale) values from 14 to 26(As in sheet d3, different value). In A1 to a13, there is serial no. from 1 to 13.
So, I want that the macro should check for sheet 1 d3 value in all worksheet, if found it will check for the serial no. against it, put the no. in E6 filed.

Sorry of I've misunderstood your question but it sounds like a vlookup might do the trick rather than the need to write VBA and use the Find method.
If you combine the second and third sheet, so that Column A contains the possible values for NAME in D3, and the Serial Number in Column B, like this.
NAME | Serial
-----|-------
1 | qwerty
2 | bob
... | ...
You can then use a LOOKUP query as follows in E6.
=VLOOKUP($D$6,Sheet2!A:B,2,FALSE)
Hope this helps.

Related

subtract the last two non-empty cell in excel

This is I think a simple problem but I can't seem to find the right solution for it. I don't know if VBA is needed for it. Basically I just want to subtract the last two non-empty cell in Excel. Example: I have the cell A1 and cell B1 and then subtract the value of A1 from B1 and place this value at the same row but another column C1 and so on. I have read this to get the last non-empty cell but I need two non-empty cell and perform operation on them.
=LOOKUP(2,1/(A:A<>""),A:A)
Is there an easier way to do this? Or should I use VBA?
EDIT:
the reason is I'm making a somewhat similar to a balance sheet but a simple one, the user will just enter deposited value at the first column and expenses at the second column and then display the balance in the third column.. and vice versa.
EDIT:
Sample
Put this in C4 and copy down:
=SUM($A$3:$A4)-SUM($B$3:$B4)
If you want to copy the formula past the data so it will automatically fill when data is inserted you can do what #Dirk stated:
=IF(A4&B4<>"",SUM(A$3:A4)-SUM(B$3:B4),"")
Put it in C4 and copy down as far as desired.
This way you can fill the column with the formula and as the data is filled it will change from the empty string to the running total.
EDIT:
Regular formula:
=IF(ROW($C1)=1,OFFSET($C1,0,-2)-OFFSET($C1,0,-1),OFFSET($C1,-1,0)+OFFSET($C1,0,-2)-OFFSET($C1,0,-1))
in cell C3 put "=A3-B3" in cell C4 put "=C3+A4-B4" then copy down.
This will start the balance at 3000 in C3 then add any deposits or minus any withdrawals to the rest of column C.

Vlookup or Match and Continuous Numbering

I am having a difficult time figuring this out and your help is greatly appreciated!
If there is the same name across multiple sheets, I would like the the number first assigned to them to populate and the remaining numbers to be in numerical order throughout the remaining sheets.
Below is sheet 1. C9 has a star near the name because it is a duplicate in sheet 2 (to follow)
Below is sheet 2. C9 is the duplicate name from sheet 1. I need the numbering for sheet 1 to remain as is and sheet 2 as 1, 8, 9, 10, 11, etc.
I am up for 2 options:
Manually enter 1 in cell B9. When I currently do this on sheet 2, the numbers start over again from 1 as opposed to the MAX number from sheet 1.
Automatically populate number when there is a name match. I have tried vlookup and match with my current formulas and they do not work with continuous numbering.
Below are my current formulas:
Cell B9, sheet 2
=MAX('Sheet 1'!B9:B66)+IF(ISTEXT(C9),1,"")
Cell B10:B66, sheet 2
=IF(ISTEXT(C10),IF(OR(ROW()=9,IF(ROW()=9,TRUE,MAX(INDIRECT("B9:B"&ROW()-1))=0)),MAX(INDIRECT("Sheet"&RIGHT(REPLACE(CELL("filename"),1,FIND("]",CELL("filename")),""),LEN(REPLACE(CELL("filename"),1,FIND("]",CELL("filename")),""))-5)*1-1&"!C:C"))+1,MAX(INDIRECT("B9:B"&ROW()-1))+1),"")
I really appreciate your time and help!!
Assuming B8 in Sheet2 is not numeric, names do not repeat within any one sheet and only two sheets are involved, I suggest in B9 of Sheet2 and copied down to suit:
=IFERROR(INDEX(Sheet1!B:B,MATCH(C9,Sheet1!C:C,0)),MAX(Sheet1!B:B,B$8:B8)+1)

Flag Data in Excel Programatially

I have two sheets in an excel workbook. One of the sheets has 8 ID numbers. The other sheet has about 5000 rows, not every row matches one of the ID numbers on the other sheet. I want to flag the rows where an ID number is an exact match to the other sheet and extract them to a separate sheet.
At the moment I was thinking I could just type in
=IF(A2=sheet2!b3,1,0) OR IF(A2=sheet2!b4,2,0) OR IF(A2=sheet2!b5,3,0) OR IF(A2=sheet2!b6,4,0) OR IF(A2=sheet2!b7,5,0) OR IF(A2=sheet2!b8,6,0) OR IF(A2=sheet2!b9,7,0) OR IF(A2=sheet2!b10,8,0)
Then copy and paste them to a separate sheet, but this doesn't work for some reason.
Any help would be much appreciated.
I didn't fix your formula for all the 8 ID's, but you should be able to add additional checks.
=IF(A2=$B$3;1; IF(A2=$B$4;2; IF(A2=$B$5;3;0)))
This basically reads as:
compare A2 with B3, if they match return 1 (note the use of $ sign in order to always use the B3 cell, this is called absolute cell reference)
if it doesn't match then compare A2 with B4 and if that matches return 2
if it doesn't match then compare A2 with B5 and if that matches return 3
if it doesn't match return 0
If you wish to compare to all 8 IDs you should just nest the if's a bit more.
A simpler solution would be to use VLOOKUP.

How to tell excel automatically add value in a cell of a sheet when the value is added in another cell of another sheet? [duplicate]

This question already has an answer here:
How to make excel automatically fill a value in a cell of a sheet when another corresponding cell of another sheet is filled the same value?
(1 answer)
Closed 8 years ago.
I have cells A1 and A2 in sheet1 with values 3, 4 respectively. I link the cell A1 and A2 to B1 and B2 in sheet2 respectively. I mean when A1 and A2 change, B1 and B2 change accordingly.
This is what I want to manipulate my spearsheet: When I add value 5 in cell A3 in sheet1, value 5 is also added in cell B3 in sheet2.
Without filling =A3 in B3 or using autofill, how can I do so?
Imagining that each time when you make a report you have to add a lot new cells -- A4 to A100 --, that the number of cells is varied each time, and that you have a lot of corresponding sheets to sheet1 -- sheet2 to sheet100 -- you will find why I need your help.
The best solution to your problem is to select the sheets on which you want the values to appear in corresponding cells by holding down the control key and clicking on sheet tab. So when you make an entry on Sheet1 in any cell the same appears in the corresponding cell of another sheet (s) selected.

Copy and paste column data based on date specified

In an Excel worksheet, cell C1 contains a date. I would like a macro that checks the date in C1 and if the same date is mentioned in row 3, then copy all matching date data beneath it from D6 downwards, paste to Sheet2, cell B3 and also copy column A downwards from row 6 to Sheet2, cell A3.
Use Excel's macro recorder to record your keystrokes and mouse actions (as Excel actions) then inspect the resulting macro. Using Excel's help, check the topic Create a macro or visit http://office.microsoft.com/en-us/excel-help/create-a-macro-HP005204711.aspx. This will get you started.
are you checking the date in C1 against any column in row 3? or in D3? or C3? It is not clear.
copy A6 down and D6 down, but switch column D to B on sheet2 and A to C on sheet2?
This could be easy if it were clearer what you are checking.