Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

Cell Color Counts - Part 3

0

Hi guys, this is more of a follow up question. Variatus helped me to solve a problem, but I need help in order to understand the fix and change the naming in some cells. The attached sheet Variatus did for me, but now for some areas I have to change the cell names e.g. 1A-1R will become 2A-2R or even A3-1R. How do I chnage this assigned fixed value or even better how do I assign a fixed value to a cell that does not even look at the conditional formatting part (1=Yellow, 2=Blue and 3=Purple) which is active?

I am also looking at a way to save this sheet, would this be possible to keep as a record or not really? I know Variatus' instrcution were not to save, just to close and re-open if needed.

Thanx for the help,

Woutie

Answer
Discuss

Answers

0
Selected Answer

You've been too shy, Woutie. I left everything blank for you to entice you to try. This is what you should get familiar with:-

  1. Look at the cell formatting.
    Right-click on a cell, select Format Cells and the Number tab in the dialog that opens. If the selected cell is in the board grid the Category list will highlight Custom and you will see the cell's format in the Type field, e.g. "1A-10R". This you can modify for every cell. Here, "1A-10R" is the default text which will be displayed regardless of the cell's true value.
  2. Make sure that none of the cells in the grid have any colour fill.
  3. Fill up the grid with a number. I suggest 0. This will make the default text in the cell format be displayed.
    Point is, if you enter zero in E3 and copy down, the cell format will be copied down along with the cell value. Therefore all cells will display "1A-1R". So, remember that pasting a cell value will also paste the cell format.
  4. You can now use the method explained in pt 1 above to reset each cell's number format or you can use the code I provided. Place the cursor in E3 and run the procedure SetNumberFormats. Just press OK when prompted for a board number. Voila! Now the entire grid shows the correct designations. Take note that changing the Numberformat doesn't change the value of the cells.
  5. If you happened to select E4 instead of E3 the number formats will all be applied to the wrong cells, including row 19 and omitting row 3. In such a case, exit without saving to get your previous cell formats back. It follows that you should save before running the code. Once the formats are set correctly, you can and should save as normal.
  6. E3 has three conditional formats set. The formulas are
    =E3=$E$28 (linked to yellow)
    =E3=$E$29 (linked to blue)
    =E3=$E$30 (linked to purple)
    Please look at these formating instructions if you aren't familar with CF. Observe that E3 is relative while $E$28 is absolute. When this CF is copied to other cells E3 is replaced with the address of the destination cell while $E$28 remains the same. Note that you can apply CF to only one cell in this way and copy its effect to other cells, along with its value and NumberFormat. You can set all three CF instructions for E3 and then copy to the other cells in the grid. Note that all CF instructions can be copied and pasted in one operation.
  7. E28:E30 contain numbers: 1 for Yellow, 2 for Blue and 3 for Purple. You might change these numbers or the addresses where they are found. Or you might even dispense with them altogether and apply yellow with a CF formula like =E3=1 which would have the exact same effect. Try it.
  8. At this point grid 1A is fully operational. Enter a number from 1 to 3 in any of its cells and see the colour change (because of the CF) and the values in E24:G27 change (because of the COUNTIF function they contain.
  9. The range E24:G27 can be copied to I24:K27. In fact, you can copy E3:G27 to I3 [:K27]. Just remember to save before you do so that you can get out of trouble if your fingers were faster than you intended them to be.
  10. Now you know that I3:K18 has the corect CF and the correct values but the wrong NumberFormat (copied from E3:G18). Therefore you need to run the procedure SetNumberFormats again, this time with I3 selected. Take the usual precaution (save before) and when the macro prompts you for the Board number enter 1B. This will change all the designations in the grid - and you're almost done: The values in row 19 will have to be corrected manually.
  11. In this manner you can add as many grids as you may require: Copy, paste, run the macro and modify row 19. If your original isn't filled with zeroes, write zero in the first cell and copy to all others before running the macro. Take note that the original cell colour is copied together with value, NumberFormat and CF, meaning if you copied a 1 and the cell is yellow for that reason, removing the 1 will return the cell's colour to its default (no colour as ensured in pt 2 above).

Of course, the sheet can be saved and reloaded and printed, just like any other sheet. From Excel's point of view it is just a standard worksheet. However, for the purpose of sending around in your office I suggest you save it in XLSX format. Nobody else will need the code because they don't know how to use it and, should they try it without instruction, face a surprise when they find all the values in their worksheet replaced with "1A-1R".

Good luck!

Edit 03 Aug 2018   =============================

As an afterthought, I suggest to keep the code in a dedicated workbook in XLSM format. Add instructions for its use to the worksheet. Keep your work in a workbook of XLSX format. Note that the code is designed to run on the ActiveSheet, meaning the starting cell you select doesn't have to be in the same workbook as the code. Just both workbooks must be open.

If you have colleagues, don't share the workbook with the code. Instead, create a template worksheet with 24 boards correctly set up. Tell them to delete the columns of boards not needed. Note that ready setup boards can be copied between sheets and even workbooks. So there really is no need for the code to be available to everyone at all times.

Discuss

Discussion

VARIATUS - YOU ARE A BLOODY LEGEND!
Thank you!

Humble
Woutie
woutie (rep: 10) Aug 2, '18 at 6:10 am
Add to Discussion


Answer the Question

You must create an account to use the forum. Create an Account or Login