I am at initial stage in creating Macros. I know how to validate one column at a time, but not sure about validating a column reference to other column in the same row. Hope someone will help me with this!
Scenario: validate 2 columns in a spreadsheet (debit and credit columns).
Condition: For every filled row, I should have one of the two column values as "0",
highlight both the columns if non of the column value is "0".
Don't use VBA, use the built-in Conditional Formatting.
Assuming those columns are A and B, let's say A2:A10 and the Credit is B2:B10.
Go to Conditional Formatting, New Rule.
Select "Use a formula to determine ..." and type in =AND($A2<>0,$B2<>0,$A2<>"",$B2<>""). Then click "Format" and Fill Red.
Then click "Ok", "Ok" and change "Applies to" range to $A$2:$B$10.
Related
Consider I have a Table A in Excel - details as below:
And another Table B as follows
I want out-put as follows,
The Name from Table B has to be checked with Name in Table A, and respective StartDate and EndDate should be picked from Table A and same should be compared with dates in Table B and cell under that name should be colored to green if Status in Table A is in "In Progress" or to Red if in "On hold"
For Example:
Consider Jack in Table B, it has 3 records in Table A, The first start date should be picked i.e 4-Apr-2017 and End date as 27-Apr-2017, and respective coloring has to be done based on status field.
How can I achieve this using VBA/anything in Excel. I'm new to VBA.
Yes you can do it in VBA but I would recommend using conditional formatting (formula) as it doesn't require programming knowledge. To do this, you will need to employ the Vlookup formula.
I believe the output you want is something in the picture link here?
To make conditional formatting, look in the "Home" tab, under Styles -> Conditional Formatting. Highlight the cell you want to format, then select Conditional Formatting -> New Rule. This will cause a new window to pop up. Select "Use a formula to determine which cells to format".
You would want 2 conditional formats.
1.To show green if the date is within the start and end date. To do so, select the first cell in the Gantt chart (cell B8 in example) then enter formula below.
=IF(AND(B$7>=VLOOKUP($A8,$A$2:$D$5,3,FALSE()),B$7<=VLOOKUP($A8,$A$2:$D$5,4,FALSE())),TRUE(),FALSE())
2.To show red when user has item beyond due date, enter formula below with same cell highlighted.
=IF(B$7>VLOOKUP($A8,$A$2:$D$5,4,FALSE()),TRUE(),FALSE())
Once that is done, you can apply the format painter or copy and paste the cell with conditional formatting to extend your table/Gantt chart.
Note that the $ signs are important as they lock the relative reference positions in the formulas. Using the second formula as an example, B$7 refers to the date and you need the reference to be locked to row 7, where all the dates are. On the other hand, the column reference (Column B) can be shifted as you want it to change to with the columns to properly compare against the other dates.
As for multiple items per user, can you expand upon your initial question? Would you like to track based on per user or per item? I am assuming that you're creating a Gantt chart to track a project. In that case, it would make more sense to track specific tasks assigned to people. You can modify the example given to track based on task.
In Excel, Office 2007, I have the option to highlight duplicate values on the menu. Keep simple! Select the column, select "Conditional Formatting" - "Highlight Cells Rules" - "Duplicate Values" and voilá! All values that were duplicate on this column it was paint with color red, for example.
Actually I use the LibreOffice Calc, version 5.0.3.2, and I can't find this option on the menu!
How can I do this job?
Select the column of numbers and note the 'active cell' (A1 in the sample image below). Go to Format ► Conditional Formatting and set up a rule as a formula using COUNTIF(A$1:A$15; A1)>1.
It is important to get the 'active cell' correct. If the 'active cell' was A15 then that formula would be COUNTIF(A$1:A$15; A15)>1.
I've also put the formula in column C so that you can see how each row resolved to TRUE or FALSE.
In LibreOffice Calc 6.0.7.3 this can be done by following these steps (from this link):
Select column A by clicking on the header character A (the top of the column)
Select the menu: Format -> Conditional -> Condition...
Condition 1: Cell value is and select duplicate from the dropdown
Apply Style: Select your cell style (e.g. Error or any you defined in advance)
Check that your cell range is A1:A1048576 (You may want to reduce the 1048576 to any reasonable number you assume will be the maximum to ever be used)
Click OK button
Not exactly the solution to this specific question, but I find the following comes in very handy when you have the column in question sorted, especially when you are sorting by multiple columns:
If you want to format any value in a cell that is a duplicate of the one immediately above it, select the entire column and use the following formula in Conditional Formatting
(INDIRECT(CELL("address"))=OFFSET(INDIRECT(CELL("address"));-1;0))
In a sorted column, the first occurrence of a value will be considered "unique" in that it hasn't occurred yet, and then all of the duplicates which follow immediately afterward are flagged (I usually use a light grey for the font color). If the column is not the major order (ie 2nd or later in the sort criteria) then the "uniqueness" is effectively "reset" each time sorting starts over for this column.
hope you are all doing well today! I've been working on a spreadsheet that tracks invoices and the hours recorded for each one. Each invoice has multiple entries with different numbers of hours for each entry, all with the same reference number which combines the project number and the invoice number. For example, for Invoice #1 of project CZ23, the reference number would be CZ23-1. Invoice 2 would be CZ23-2, and so on. This is located in Column I, while the hours are located in Column H in a sheet named "Document Data".
Now I have another sheet that tracks the hours called "Summary". What I want to do is have cell B28 of "Summary" add up all the hours from CZ23-1 from "Document Data". Since I barely know any VBA, I don't have code but I'll display the situation here:
In this case, cell B28 on "Summary" would be 15 (all the CZ23-1 hours added up: 2+5+1+7), while B29 would be 7 (all the CZ23-2 hours added up: 4+3) and so on. It doesn't necessarily have to be B28/B29, but just as a reference I've used those cells. Thank you so much for your time - hope I was able to explain everything well.
Best way to do this would be to create a pivot table.
1. Select a cell inside your data and then on the insert tab select pivotTable.
2. A "Create PivotTable" box will pop-up. Verify that your data is captured in the Table/Range. Also, you can choose if you want to have the table appear on a new sheet or the existing sheet.
3A. In the "PivotTable Fields" box, you can drag "Reference" to the Rows box and then drag "Hours" to the Values box. This should default to Sum and should add up all the Hours by Reference.
3B. Occasionally the Values box will default to Count. To change this to SUM, you can select cell B4 or B5 (See Below). Right click and select Value Field Settings. When the "Value Field Settings" box pops-up, you can select Sum on the "Summarize Values By" tab.
It sounds like you want the sql concept of 'group by' on column 'Reference'
In excel you can do this by using pivot tables
You will find pivot tables in the toolbar at Insert-->Tables-->PivotTable
How can I automatically fill data into a specific column by referring to a different source-column on the same sheet?
Example:
In the source column are the numbers 1 to 10. How can I convert this into e.g. having "1" displayed as "One" in the second column?
If you just want to spell the number in the first column, then:-
Setup your column headers and format the area as a table (From Ribbon -> "Home" => "Format as Table").
Using the instructions from this Microsoft Support article (https://support.microsoft.com/en-us/kb/213360/en-us), add the code from the article into a VBA Module in the workbook.
Assuming your first data cell is "A2", add this formula to cell "B2":- =SpellNumber(A2). Since it is a table, the formula will be propagated down that entire column automatically, even when adding new rows.
You will need to modify the code from the MS Support article, as it is designed for returning Dollars & Cents phrases.
without know that you really want, You can see convert a numeric value into English words in Excel
PS: joehanna sorry, I'm not saw your answer
I'm trying to get a msgbox when a value is duplicate base on 2 columns. The first column Value can be repeated but the second column will determine if it's a duplicate or not.
i.e.
Column B = Code,
Column L = Month
The user can enter the Code several times, but if he enters it on the same month I want the msgbox pop up
Is your intention to warn\inform the user? If so, I would do this without a macro. I would use conditional formatting to make the cell change color whenever the duplicate information is entered.
Create a column on your worksheet with a formula that concatenates the information in column B&L the formula would be =B1&L1 (copy this formula down the table). You can hide the column so nobody sees it. For this example, let's say you used column "M".
Select the entire Code or Month column (or both) and click the CONDITIONAL FORMATTING button on the Home tab, choose NEW RULE, USE FORMULA TO DETERMINE WHICH CELLS TO FORMAT, then enter the following formula: =COUNTIF($M$4:$M$1000,M1)>1 (note I am assuming your range of data is less than 1000 records, otherwise increase that number). Set the format to something like a red fill and instantly duplicates will be flagged. The user will also be able to quickly locate the record where this combination was already entered as that will turn red too.
If you really do want a macro to do this, you could simply write a loop to compares the active cell value of B(activerow) & L(activerow) to each previous B#&L# combination. If a match is found, use the intersect method to pop-up a the message. Here is really a good article about the intersect method: http://www.ozgrid.com/VBA/vba-intersect.htm.