Matching of cells in excel - excel

It Sum of columns is storing in one cell and if I want the same answer to be printed in another cell, what is the formula to get this?

Let's say your sum is stored in B1 and you want same in C1 then you can do
=B1
inside C1 cell

Let's say you want the value of cell A1 in cell B1. You would use this formula in B1:
= A1
In code you would write something like this (example in VBA):
Dim sht as Worksheet
Set sht = ThisWorkbook.Worksheets("MySheet") //Or whatever your target sheet is
sht.Range("B1").Formula = "=" & sht.Range("A1").Address

Related

Returning a value from a worksheet to another

I have a spreadsheet with two worksheets, A & B.
I need a formula that will look at a value in cell B2 in worksheet A and return the value in cell F2 in worksheet A to cell C2 in worksheet B.
So. If the value in B2 is individual the formula will return the Value in F2, e.g., "Smith", to cell C2 in worksheet B.
How can I do that?
So, like this:
=IF('Sheet A'!B2="individual",'Sheet A'!F2,"Blank")

copying a formula from another sheet and pasting it to master sheet

This might be too easy for many but i need an help.
I have following formula in Sheet1 which takes the value from Sheet2 M3 Cell
='Sheet2'!M3
M3 cell in Sheet2 has a formula inside which is following:
=INT(NETWORKDAYS(K3;L3)/5)+1
I want to paste the formula inside M3 to my formula in Sheet1 but when i do this as following i get an error.
='Sheet2'!INT(NETWORKDAYS(K3;L3)/5)+1
Can anyone tell me what is wrong here and how i can paste this formula correctly so it works?
Your question was a bit confuse, but:
Do you want the NETWORKDAYS formula to get data from Sheet1 itself?
If yes, just erase the 'Sheet2'! part of your formula.
2. Do you want the NETWORKDAYS formula to get data from Sheet2?
If yes, this is the final formula:
=INT(NETWORKDAYS('Sheet2'!K3;'Sheet2'!L3)/5)+1
The problem is that you should use Sheet reference ('Sheet2'!) before cells, not before formula, so that Excel knows where it should get the data.
say we have:
Sheet1 cell A1 contains the formula:='Sheet2'!M3Sheet2 cell M3 contains the formula:=INT(NETWORKDAYS(K3;L3)/5)+1Select the A1 cell and run this short macro:
Sub FormulaGrabber()
Dim s As String, r As Range
With ActiveCell
s = .Formula
Set r = Range(s)
s = r.Formula
.Formula = s
End With
End Sub
The macro will go to Sheet2, grab the formula in M3 and put it back in Sheet1

Summing two columns together (each cell separately)

I'm using Excel and I've just started using vba in Excel.
I need to add the values of column I, cells I6:I26 in sheet 1 to column D, cells D1:D21 in sheet 2.
So if I6 = 4 and D1 = 6, and I press the ADD button, D6 will equal to 10. Same goes for the rest of the cells.
I don't want it cell I6 to replace the value of D6, I want it to add to it.
This is the code I have so far for it;
Dim r1 as Range, v as variant
Set r1 = Sheets("Sheet2"). Range("D1")
V = Application.WorksheetFunction.Sum(Sheet1.Range("I6"), Sheet2.Range("D1"))
R1 = v
I had to do that 20 times..is there anyway to simplify this?
You can Evaluate the sum of arrays:
[Sheet2!D1:D21] = [Sheet1!I6:I26 + Sheet2!D1:D21]
I'm finding it a bit confusing where you want the result to go. Sheet1 has data in I6:I26 and Sheet2 has data in D1:D21.
You want the first result to go into cell D6... on what sheet? On Sheet2 so it starts overwriting the old data, in Sheet1? Some other sheet?
This code will place a formula in cell D6 on sheet 1 and drag it down to cell D26.
I've given two types of formula. A1 notation and R1C1 notation.
A breakdown of the R1C1 notation:
RC9 means take data from this row, column 9 - in cell D6 this will be cell I6.
R[-5]C4 means take data from 5 rows up in column 4 - in cell D6 this will be D1.
Sub Test()
With Sheet1
.Range("D6").Formula = "=SUM($I6,Sheet2!$D1)"
'You could also use R1C1 notation (which is easier if you're looping through rows/columns).
'.Range("D6").FormulaR1C1 = "=SUM(RC9,Sheet2!R[-5]C4)"
.Range("D6:D26").FillDown
End With
End Sub

How to vlookup each comma separated value in one cell?

I have worksheet A:
I have another worksheet (WS) B:
What I want:
I wanna use a Vlookup formula at cell C3 with the formula like this:
=VLOOKUP(B2,b!A2:B3,2,FALSE)
However:
I don't know how to make it look up multiple comma separated values (csv) in one cell (Note that there are cells that can go up to 10 csv)
Logic wise, cell C3 of WS A should :
Lookup value B2
From the table array of WS B
Looping through cell A2 of WS B, it should check for "1-ABC", "2-ABC", "3-ABC".
Since it finds a match at "3-ABC" then C3 will return the Unique Acc ID at B2 of WS B
Then hopefully I can drag down the formula to many many records...
Can this be done using formula or it better to do it via VBA? If VBA, how can I do this?
You can use the asterisks as wildcard like that
=VLOOKUP("*" & B2 & "*",b!A2:B3,2,FALSE)

Using each cell in a range within a formula and returning the result in the same cell?

I suppose this should be easy, but - how do I extract a value from each cell in a range, place that value in a formula, and return the result in the same cell that the original value came from?
Example: (simplified :-))
I already have values entered in a range (say A1:A3): A1=2.1 ; A2=0.78 ; A3=1.1. I also have a specific factor in D1 e.g. D1=0.4, and a specific formula that I want to use: exp(ln(value)/factor). What I want to do is:
extract the value in A1 (=2.1) and
place it in the formula together with the factor in D1 (=exp(ln(2.1)/0.4))
and put the result back in A1 (=6.39)
...and so on for A2 (=0.54), A3 (=1.27)......
As my range is very large, covering several sheets, I´m thinking some kind of "for each cell in range(myRange)" function, but I haven´t been able to figure it out...
To accomplish this, try the following:
Dim rng As Range, Cell As Range
Then set your Range:
Set rng = Range("A1:A3")
Then begin your For Each loop:
For Each Cell In rng
Cell = Exp(Log(Cell)/Range("D4"))
Next Cell

Resources