Excel I need it to delete what I type right after I press enter is this possible? This might be easy but I don't know how to.
Yes I am using this data I need it to send the data and then delete itself with the results from that data in.
This is what I have so far: "=COUNTIF(B2;C8)" so if the b2 matches c8 then it adds one and I need it to delete the b2 automatically so that I could enter new value.
Go to File > Options. This will open a window, select the second tab Formulas. Check the box Enable Iterative Calculation.
Note, that this box will uncheck itself if you install updates.
Ta da!!!
Place the following event macro in the worksheet code area:
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
Target.ClearContents
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
I've specified in cell "B1" where my sheet needs to be opened on (=MATCH(TODAY(),A:A,0)).
And I want to automatically open my excel sheet on that row.
(example: row 10 = today)
or can I use the function "=today()" in VBA ?
I'm kind of a noob in VBA so can you please assist me ?
Place the following Event Macro in the worksheet code area:
Private Sub Worksheet_Activate()
Cells(Range("B1").Value, "A").Select
End Sub
When the worksheet is opened, the proper cell will automatically be Selected:
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!
EDIT#1:
To get the same behavior when the file is opened, leave the previous macro in place and put this macro in the workbook code area:
Private Sub Workbook_Open()
Application.EnableEvents = False
Sheets("Sheet1").Select
Cells(Range("B1").Value, "A").Select
Application.EnableEvents = True
End Sub
(you would replace Sheet1 with the name of your worksheet)
A friend of mine works at Verizon and asked me If excel has built in functions for whenever he types "open" into a cell it will return "8:30-5:00" into that cell.
I hounded google for an hour. I cant seem to find what I am looking for.
Thank you.
You can use Custom functions in Excel. Custom functions, like macros, use the Visual Basic for Applications (VBA) programming language.
https://support.office.com/en-us/article/Create-Custom-Functions-in-Excel-2007-2f06c10b-3622-40d6-a1b2-b6748ae8231f
You need a Worksheet Event Macro. This is a small routine that will constaintly monitor cells on a worksheet and take action if data is typed into them.
Say we want to monitor cell B9. Include the following in the worksheet code area:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim B9 As Range
Set B9 = Range("B9")
If Intersect(Target, B9) Is Nothing Then Exit Sub
If B9.Value <> "Open" Then Exit Sub
Application.EnableEvents = False
B9.Value = "8:30-5:00"
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!
A non-VBA solution is possible using Excel's built-in Autocorrect facility.
On the File tab in Excel 2013 click Options -> Proofing -> Autocorrect and enter "open" in the Replace: box and "8:30-5:00" in the With: box (without the quotes).
This is not case sensitive so will work for both "open" and "Open".
If you are ever likely to want "open" or "Open" to appear in a string you could add an escape character such as backslash to your replace string "\open".
In Excel, is there any way to write a function in cell A1 that sets the value of B2 to 5. I need to do this without inputting any function or reference into cell B2. Thanks for your help.
In A1 enter the formula:
=A2
and in the worksheet code area, enter the following Event macro:
Private Sub Worksheet_Calculate()
If Range("A1").Value = 5 Then Range("B2").Value = 5
End Sub
Now if you enter a 5 into cell A2, it will also get entered into 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!
Im trying to get a msgbox when the value in the cell which is updated with a formula is less than zero.
For example:
a1= 5
b5= a1
if b5 is less than zero then msgbox "your value is less than zero"
Hope someone can help me
Thank you!
Include the following event macro in the worksheet code area:
Private Sub Worksheet_Calculate()
If [B5] < 0 Then
MsgBox "your value is less than zero"
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!
I want to be able to set values in a cell but prevent the cell from being changed easily afterwards.
The cell will store a random int and so if the user edits the cell and presses enter a new random int is generated. These id's are mapped to unit tests so updates are undesirable.
How could I solve this please?
Here is a simple example for a single cell, cell B9.
It assumes that we start with all cells UNLOCKED
Enter the following event macro in the worksheet code area:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim B9 As Range
Set B9 = Range("B9")
If B9.Value = "" Then Exit Sub
If Intersect(Target, B9) Is Nothing Then Exit Sub
B9.Locked = True
ActiveSheet.Protect Password:="secret"
End Sub
Once a value in entered in B9, that cell is locked and the worksheet is protected with the password secret.
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!