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".
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)
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!
I am trying to create in excel where you enter initials into a cell and the person's full name appears automatically so they do not have to enter their full name every time in a spreadsheet. I have managed to replicate this using nested if statements for different people which works fine but currently it requires two cells and I want to have it on the same cell. I have noticed that if I change the the formula to be in the same cell then it comes up with "circular reference warning" and does not work and if I try to enter text in that cell it replaces the formula. Just wondering is this possible?
=IF(C29="HB", "hazel", IF(C29="AO", "amelia", ""))
You could use Excel's AutoCorrect feature to do this.
Go to File..Options..Proofing -
Click on AutoCorrect Options..
Enter a pair (or triplet) of initials you want to replace and the name you want the initials to be replaced with, then click add. You can then continue adding Replace With definitions.
It doesn't matter if you enter the Replace in lower case "hb" or upper case "HB" because the entry and its replacement are both added to the definitions in lower case.
Excel does this for a reason - it is sensitive to the case of the cell entry. That is to say if you enter "hb" the autocorrect will change this to "hazel"; if you enter "Hb" you will get "Hazel"; and "HB" will give you "HAZEL".
The replacement pairs you enter will only apply to the currently logged username. The replacement pairs will be there every time you open Excel and are available to all open workbooks.
If you want the replacement pairs to be available to other users you will need to:
manually add the replacement pairs to all desired users Excel Options or
develop a macro to add them using Application.AutoCorrect.AddReplacement "hb", "hazel"
If you decide to go down the macro path, you may want to limit the scope of definitions by entering them in certain workbook or worksheet events and consider using the Application.AutoCorrect.DeleteReplacement "hb" method.
Workbook_Open
The replacements will be available to the current user in all workbooks and will remain until the are deleted manually or programmatically.
Workbook_Activate and Workbook_Deactivate
If you use the AddReplacement method in Workbook_Activate and the DeleteReplacement method in Workbook_Deactivate then the replacements will only be available to sheets in the workbook containing the code.
Worksheet_Activate and Worksheet_Deactivate
Place the code in a sheet module within the above sheet event handlers and the replacements will only be available in the sheet corresponding to that module.
This is just an example that you can adapt to your needs. The initials input will be in column A so if the user types JW in a cell in that column, the cell will change to James Ravenswood.
Put the following event macro in the worksheet code area:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim A As Range
ary = Array("JW", "VL", "BJM")
bry = Array("James Ravenswood", "Victor Laszlo", "Bullwinkle J Moose")
Set A = Range("A:A")
If Intersect(Target, A) Is Nothing Then Exit Sub
v = Target.Value
For i = LBound(ary) To UBound(ary)
If v = ary(i) Then
Application.EnableEvents = False
Target.Value = bry(i)
Application.EnableEvents = True
Exit Sub
End If
Next i
End Sub
You would need to fill ary and bry with your initials and names.
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!