Function referring to the last entered cell in a column - excel

I want a function that refers to the last entered cell in a particular column. For example, consider column A and the entries are as follows.
1st entry in column is in cell A1,
2nd in A2, 3rd in A5, 4th in A8, 5th in A7.
Now i want a function that refers to the cell A7.

With data in column A use
=LOOKUP(2,1/(A:A>0),A:A)
For example:
Will display Albert

Here is the macro approach. The macro monitors changes made to column A and records the last value in cell B1
Insert this event macro in the worksheet code area:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim A As Range, B As Range
Set A = Range("A:A")
Set B = Range("B1")
If Intersect(A, Target) Is Nothing Then Exit Sub
Application.EnableEvents = False
B = Target.Value
Application.EnableEvents = True
End Sub
Because it is worksheet code, it is very easy to install and automatic to use:
right-click the tab name near the bottom of the Excel window
select View Code - this brings up a VBE window
paste the stuff in and close the VBE window
If you have any concerns, first try it on a trial worksheet.
If you save the workbook, the macro will be saved with it.
If you are using a version of Excel later then 2003, you must save
the file as .xlsm rather than .xlsx
To remove the macro:
bring up the VBE windows as above
clear the code out
close the VBE window
To learn more about macros in general, see:
http://www.mvps.org/dmcritchie/excel/getstarted.htm
and
http://msdn.microsoft.com/en-us/library/ee814735(v=office.14).aspx
To learn more about Event Macros (worksheet code), see:
http://www.mvps.org/dmcritchie/excel/event.htm
Macros must be enabled for this to work!

Related

formula changing the original cell's value

It might be a strange question, but is it possible to use a formula that changes the original cell's value to the outcome of that formula?
for example: I fill in C5 "10", and I inserted a formula there that multiplies it by 5, so the value in C5 will change to "50"
of course it mustn't make a loop, multiplying every new value by 5 so the cell will soon be too small for the number. (10)*5)*5)*5)*5)*5....
only once.
I hope this is possible although I don't think so.
Cheers,
Bart.
Say we enter values in cell C5 and want to have the value automatically multiplied by 5 each time we enter a new value.
Place the following Event Macro in the worksheet code area:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim C5 As Range
Set C5 = Range("C5")
If Intersect(Target, C5) Is Nothing Then Exit Sub
Application.EnableEvents = False
C5 = 5 * C5
Application.EnableEvents = True
End Sub
Because it is worksheet code, it is very easy to install and automatic to use:
right-click the tab name near the bottom of the Excel window
select View Code - this brings up a VBE window
paste the stuff in and close the VBE window
If you have any concerns, first try it on a trial worksheet.
If you save the workbook, the macro will be saved with it.
If you are using a version of Excel later then 2003, you must save
the file as .xlsm rather than .xlsx
To remove the macro:
bring up the VBE windows as above
clear the code out
close the VBE window
To learn more about macros in general, see:
http://www.mvps.org/dmcritchie/excel/getstarted.htm
and
http://msdn.microsoft.com/en-us/library/ee814735(v=office.14).aspx
To learn more about Event Macros (worksheet code), see:
http://www.mvps.org/dmcritchie/excel/event.htm
Macros must be enabled for this to work!

Excel IF a cell value is bigger then previous value of the same cell

I would like to put a value to A1 and when I changed A1 I want to keep the first entered value in another cell.
Would that be possible ?
Thanks
Insert the following event macro in the worksheet area:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim A As Range, N As Long
Set A = Range("A1")
If Intersect(Target, A) Is Nothing Then Exit Sub
If Cells(1, 2).Value = "" Then
N = 1
Else
N = Cells(1, 2).End(xlUp).Row + 1
End If
Application.EnableEvents = False
A.Copy Cells(N, "B")
Application.EnableEvents = True
End Sub
Every time you enter a value in A1, that value will be recorded in the first availab1e cell in column B
Because it is worksheet code, it is very easy to install and automatic to use:
right-click the tab name near the bottom of the Excel window
select View Code - this brings up a VBE window
paste the stuff in and close the VBE window
If you have any concerns, first try it on a trial worksheet.
If you save the workbook, the macro will be saved with it.
If you are using a version of Excel later then 2003, you must save
the file as .xlsm rather than .xlsx
To remove the macro:
bring up the VBE windows as above
clear the code out
close the VBE window
To learn more about macros in general, see:
http://www.mvps.org/dmcritchie/excel/getstarted.htm
and
http://msdn.microsoft.com/en-us/library/ee814735(v=office.14).aspx
To learn more about Event Macros (worksheet code), see:
http://www.mvps.org/dmcritchie/excel/event.htm
Macros must be enabled for this to work!
Here is a solution using formulas, only. It requires that you switch the iterative calculations on in Excel options.
You can set it to 1 iteration.
You only need to enter the following formula into B1:
=IF(ISBLANK(C1),IF(ISBLANK(A1),B1,IF(B1="",A1,B1)),"")
A1 is the cell whose value is to be remembered, B1 is the memory location, C1 is the reset button.
As long as C1 is empty, B1 holds the very first value entered into
A1.
When you enter any value in C1, B1 becomes empty and blocked in
this state.
You can then delete the content of C1, and B1 will become responsive again. It will "catch" the first value present A1 and keep it until you reset it again.

In excel how do i make cells in a column/row clickable?

In excel how do i make cells in a column/row clickable?
I have a data grid and want to be able to click on a cell in column N and have that data in that cell appear in another cell.
I also want to be able to click on a cell in row 3 and have that data appear in a second cell.
(Table begins at column N and row 3)
Here is a method for double click
Enter the following event macro in the worksheet code area:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim Reg As Range, B2 As Range
Set Reg = Union(Cells(1, 1).EntireRow, Cells(1, 1).EntireColumn).Cells
Set B2 = Range("B2")
If Intersect(Target, Reg) Is Nothing Then Exit Sub
Cancel = True
B2.Value = Target.Value
End Sub
If you double click on a cell in column A or row#1, its value will appear in cell B2
Because it is worksheet code, it is very easy to install and automatic to use:
right-click the tab name near the bottom of the Excel window
select View Code - this brings up a VBE window
paste the stuff in and close the VBE window
If you have any concerns, first try it on a trial worksheet.
If you save the workbook, the macro will be saved with it.
If you are using a version of Excel later then 2003, you must save
the file as .xlsm rather than .xlsx
To remove the macro:
bring up the VBE windows as above
clear the code out
close the VBE window
To learn more about macros in general, see:
http://www.mvps.org/dmcritchie/excel/getstarted.htm
and
http://msdn.microsoft.com/en-us/library/ee814735(v=office.14).aspx
To learn more about Event Macros (worksheet code), see:
http://www.mvps.org/dmcritchie/excel/event.htm
Macros must be enabled for this to work!

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?

For example, I have cell A1 in sheet 1 and its value is "yes". If I fill in the cell A1 in sheet2 ='sheet1'!A1 then we know what is going on. However, how can I make the cell A2 in sheet2 also have "yes" when I fill in cell A2 of sheet1 without filling in cell A2 of sheet2 ='sheet1'!A2 ?
In other word, I want to make excel automatically fill a cell of sheet2 each time when I fill a value in corresponding cell of sheet1.
Enter the following event macro in the Sheet1 code area:
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
Dim r As Range
For Each r In Target
addy = r.Address
Sheets("Sheet2").Range(addy).Value = r.Value
Next r
Application.EnableEvents = True
End Sub
Because it is worksheet code, it is very easy to install and automatic to use:
right-click the tab name near the bottom of the Excel window
select View Code - this brings up a VBE window
paste the stuff in and close the VBE window
If you have any concerns, first try it on a trial worksheet.
If you save the workbook, the macro will be saved with it.
If you are using a version of Excel later then 2003, you must save
the file as .xlsm rather than .xlsx
To remove the macro:
bring up the VBE windows as above
clear the code out
close the VBE window
To learn more about macros in general, see:
http://www.mvps.org/dmcritchie/excel/getstarted.htm
and
http://msdn.microsoft.com/en-us/library/ee814735(v=office.14).aspx
To learn more about Event Macros (worksheet code), see:
http://www.mvps.org/dmcritchie/excel/event.htm
Macros must be enabled for this to work!

Make an excel cell mandatory, based on value of other 2 cells

So.. I've an excel where 2 consecutive cells can be marked with the same value (mostly Text), based on this 2 cells the value of the 3rd cell should be filled mandatorily by the user.
The range of cells can be different as I need to use the same snippet cross many excels.
Any help would be sincerely appreciated.
Many thanks! :)
There's more then one way to skin a cat, but probably the easiest way to do it would be to include a vba sub which (on some trigger, like submitting) checks the value of cell 1 and 2 and IF that value is whatever you want to trigger on... if cell 3 is blank prompt the user to fill in box three.
IF Range("A1").Value == "Trigger" And Range("A2").Value == "Trigger" And Range("A3") == "" Then msgBox("You must fill in cell A3")
If you add a break statement like End Sub, the sheet can't continue until that cell is filled.
This is an example for A1, B1, C1 enter the following event macro in the worksheet code area:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim A As Range, B As Range, C As Range
Set A = Range("A1")
Set B = Range("B1")
Set C = Range("C1")
If A <> "" And B <> "" And C = "" Then
Application.EnableEvents = False
C.Select
Application.EnableEvents = True
MsgBox "please enter a value in cell C1"
End If
End Sub
Because it is worksheet code, it is very easy to install and automatic to use:
right-click the tab name near the bottom of the Excel window
select View Code - this brings up a VBE window
paste the stuff in and close the VBE window
If you have any concerns, first try it on a trial worksheet.
If you save the workbook, the macro will be saved with it.
If you are using a version of Excel later then 2003, you must save
the file as .xlsm rather than .xlsx
To remove the macro:
bring up the VBE windows as above
clear the code out
close the VBE window
To learn more about macros in general, see:
http://www.mvps.org/dmcritchie/excel/getstarted.htm
and
http://msdn.microsoft.com/en-us/library/ee814735(v=office.14).aspx
To learn more about Event Macros (worksheet code), see:
http://www.mvps.org/dmcritchie/excel/event.htm
Macros must be enabled for this to work!

Resources