VBA Pop-up Message Code - excel

I am trying to figure out how to display a pop-up if the value in a cell exceeds a certain value.
I have a worksheet that tracks the absences of employees per day. The names are in column A while the dates are in rows D to AH. I have a formula in D15 that counts the absences of employees on say D33 to D50.
What I'm looking for is a code to display a message box if the value of cell D15 exceeds 4. Then have the pop message applied from D15 to AH15. Then I want to restrict the message per cell. I also need to have it set up for E16 to AH16.
Then how do I apply it for each month but all in the same worksheet?

You can do it 2 ways at least:
Use VBA: Add the on worksheet change event to the worksheet (http://msdn.microsoft.com/en-us/library/office/ff839775(v=office.15).aspx) and add an if statement to check the changes in the cells you need e.g. D15. In response show the message. This has 1 setback - you will not be able to do CTRL+Z (undo) operations as when VBA executes it cancels the log of modified operations.
Simply add a column with a formula asserting the condition in D15. In response may the formula simply show text with the message. You can also use conditional formatting to change the cell background (e.g. to red).

Related

Write N/A or " - " on empty cells if one cell of the same row is written

What I am trying to do is this;
I have a table with 8 columns.
What I am trying to do is when I write something in one of the first 4 columns in the same row the other 3 should return me with the value "N/A" or " - ", or something like that. (Or even better with an error message saying I can't write on them since one of the other is written).
The same with the other rows in the table.
Here is the table:
table
I've tried with IF(OR(ISBLACK( etc. but it wasn't working.
So if i write something on cell B3, the other cells (C3,D3,E3) will have to be empty, the same as if i write something on cell C3, the other cells(B3,D3,E3) should be empty.
You could do this using formulas, with each column have a formula that checks the other columns. For example, B3 would have:
=IF(OR(C3<>"",D3<>"",E3<>""),"Do not use","")
But the problem with formulas in data entry spaces is they get overwritten when users enter data. If the user changes their mind and deletes the value they entered, you don't get the formula back and warning won't reappear when they enter data elsewhere.
Instead, you can use conditional formatting to change the colour of cells without values after a value gets entered:
Select B1:E16 (starting from B1 is important, as relative conditional formatting depends on which cell is active within the selection)
Create a new Custom Formatting rule based on a formula: =AND(COUNTA($B3:$E3)>0,B3="")
Set the format to make the background gray
This doesn't stop users entering data in more than cell. You may want to put in another additional conditional formatting rule to set cells red if there is more than 1 value entered.

Accessing ActiveX textbox value from cell formula

I cannot post my code because it is company property, but the issue is that I would like to enter a cell formula so that it automatically updates when particular other cells change.
I have two columns, one for prices in USD and another for another currency. The other currency column is a simple "=SUM..." but the currency conversion to USD is always changing, and the prices are large enough that these changes matter. As such, I have the user enter the conversion value in the activex textbox, and I want to set the formula of the USD cells to be the price in USD, so obviously I need to get this conversion value, but I cannot just type in the textbox name, that does not work.
I am using VBA, but I would like to enter this directly into the cell as "=FORMULA", where formula contains the activeX textbox value, so that it automatically updates.
As far as I have found in VBA, if I want to assign a formula to a cell, I have to do so within a sub or function, so I have to call the sub every time I want to update the cells, but I want this to be as automatic as Excel is for other cell formulas.
I have been playing with Worksheet_Change and considered worksheet_open but have had other issues. For example, there are many different cells that could change that I have to monitor for change, and I cannot simply monitor the price column in the other currency for change because when cells update from a formula, Worksheet change does not show those cells as having changed.
Maybe this is as simple as setting the cell formulas on worksheet_open, but I also have not had luck with getting cell.formula to even work. I could discard the textbox for a regular cell which would totally solve this problem, but I also have a textbox_lostfocus sub that I need to run, and I don't know how to do that for a cell.
Sorry for the long post, in summary, how can I assess a textbox value for use in a cell formula ideally without using vba?
This is what linked cells are for. You link your ActiveX textbox to a cell. The cell value then gets updated once you update the value of your textbox. You can reference this cell in your normal excel formulas. See here for a tutorial: https://analysistabs.com/vba-code/activex-controls/textbox/

Highlighting cells in a column based on other cells dates in the same row

I have a spreadsheet that is used to track the last date a set of logs was downloaded.
We need to take logs at around the 7 day mark if possible (not critical)..
We have approximately 170 assets that we do this to.
The way the spreadsheet is set up the new date is added to an ever expanding list (rather than just overwriting) i have used conditional formatting to show that a date is less than 7 days old but that cell can be 20 columns accross and is still hard to cross reference to the asset number. I want to highlight column A if any other cell in the same row is highlighted (unless you have a less clunky way of doing it, having the date highlighted really is unimportant it is simply as far as i can get on my own.
I even tried doing a sort by cell colour but that seems to require that i pick one coulmn only.
Thanks for your help.
Conditional formatting will do this for you. I used this example:Column A has dates, Columns B and C have miscellaneous gibberish. (click the link to view the image)
Select the entire range of cells you want to follow these rules (possibly just "select all" to be sure you are getting future additions as well, then choose Conditional Formatting from the ribbon.
Conditional Formatting > Use a formula to determine...
Then enter the following code. =TODAY()-$A2<7 Update $A2 with whatever cell contains your first date value, and be sure to put a $ in front of its column reference so that the formula references only your date column and doesn't wander.Code: =TODAY()-$A2<7
Click the "Format" button to set whatever format you like (I chose yellow fill).

How to conditional format based on multiple specific text in Excel

I have a spreadsheet that i use to determine when/what clients to contact when an issue arises. in the first workbook i insert a column every day and paste in information about any questionable habits from clients, including a client ID. unfortunately the data i am copying from also includes clients that are not to be contacted during an issue. i have a second page that has listed in column A all of the "dont check" client ids. is there a way to conditional format the original page to color any cells referencing a "dont check" client based upon the don't check listing in sheet 2?
EDIT: there is more than just client ID in the first sheet cells. client id is just included. the format is [(last file received date)(Client Name)(Client ID)(Last X file received date) (Last Y file received date)] all in one cell.
In theory what i would like is to go to conditional formatting, highlight cell rules, text that contains... then select A1-A45 on Sheet2 and click okay. obviously this is not possible. an error shows up stating "this type of reference cannot be used in a Conditional Formatting formula. Change the reference to a single cell, or use the reference with a worksheet function such as =SUM(A1:E5)
Thanks in advance.
You can use MATCH for instance.
Select the column from the first cell, for example cell A2 to cell A100 and insert a conditional formatting, using 'New Rule...' and the option to conditional format based on a formula.
In the entry box, put:
=MATCH(A2, 'Sheet2'!A:A, 0)
Pick the desired formatting (change the font to red or fill the cell background, etc) and click OK.
MATCH takes the value A2 from your data table, looks into 'Sheet2'!A:A and if there's an exact match (that's why there's a 0 at the end), then it'll return the row number.
Note: Conditional formatting based on conditions from other sheets is available only on Excel 2010 onwards. If you're working on an earlier version, you might want to get the list of 'Don't check' in the same sheet.
EDIT: As per new information, you will have to use some reverse matching. Instead of the above formula, try:
=SUM(IFERROR(SEARCH('Sheet2'!$A$1:$A$44, A2),0))
Suppose your "Don't Check" list is on Sheet2 in cells A1:A100, say, and your current client IDs are in Sheet1 in Column A.
What you would do is:
Select the whole data table you want conditionally formatted in Sheet1
Click Conditional Formatting > New Rule > Use a Formula to determine which cells to format
In the formula bar, type in =ISNUMBER(MATCH($A1,Sheet2!$A$1:$A$100,0)) and select how you want those rows formatted
And that should do the trick.

How to set a 0 default value within a range of cells?

I am using a range of cells (columns F-G-H) for estimation purposes, and having an estimate of 0 hours is acceptable, however blank/empty is not. Seeing as users can add rows as they see fit I want to ensure that all cells in columns (F-G-H) except for the header (row1) default to 0 (and the user can change / overwrite it) if needed.
Is there a way I can enforce this for newly created rows for this specific range? I know I can use a formula in the existing cells but that doesn't help for rows that are user-created after the fact.
(BTW - simularily for column C I want to default the cell to "WI-" and for column D I want to default the cell to "REQ-", etc...).
Any help/hints/ideas would be much appreciated.
Thanks,
Do this.
Enter the number 1 in an unused cell
Copy that cell.
Highlight the cells in which you want blanks replaced by zeros.
Choose Edit > Paste Special from the menu.
In the Operation section of the dialog box select Multiply and click on OK.
Numeric cells won't change and Cells containing any text data will be ignored.
All blank cells will now contain a zero.
For this to apply to newly added rows, use the Worksheet_Change event in which you will predefine your range where this will be applicable. Simply record a macro for the above steps and use that code in the Worksheet_Change event.
Also remember to use proper error handling and set Application.EnableEvents = False and reset it again in the error handler.
(BTW - simularily for column C I want to default the cell to "WI-" and for column D I want to default the cell to "REQ-", etc...).
For this the above method will not work. You will have to handle that in VBA

Resources