Coloring the cell's in workbook using Macros

Hello Guru's,
Here I got issue,
We have Report executed in the Excel, and after that we have to make another sheet(workbook) to calculater all the Before year values , Actual Year values and then the Planned values. We did calculater the varience and Percentage of the varience. All this is ok. i was pretty much able to manage.
But here the question i am putting in front of you guyus is , we have to cloror the cells of the Percentage column base on the threshold or bias like if
cell values is >= 0 it should be red
cell value is  < 0 it should be Green
cell value is < -0.5 it should be yellow.
i have been looking around in the forums all day, and i am very new to Macros.
I did go through Peter Knoer forums.
Hope i get a good reply from you guys,
Thank& Regards,
Kiran

Thank you Dash,
you gave me a good idea for me, But here i got one problem,
i got the code , but i want to do it for 4 colums, for all the 4 colums i am reprting the code , i want to avoid the repetion of the same code, how would i do that.
i am giving the code for 2 colums below.
can me plz help on this.
Sub Sheet1()
    Dim i As Integer
    Dim j As Integer
    Dim k As Integer
    Dim l As Integer
    For i = 10 To 39
        For j = 2 To 2
            If Cells(i, j) >= 0 Then
                With Cells(i, j).Interior
                .ColorIndex = 0
                .Pattern = xlSolid
                End With
                Else
             If Cells(i, j) < 0 And Cells(i, j) >= -0.5 Then
                With Cells(i, j).Interior
                .ColorIndex = 6
                .Pattern = xlSolid
                End With
             Else
                With Cells(i, j).Interior
                .ColorIndex = 3
                .Pattern = xlSolid
                End With
            End If
            End If
        Next j
        Next i
        For k = 10 To 39
         For l = 5 To 5
            If Cells(k, l) >= 0 Then
                With Cells(k, l).Interior
                .ColorIndex = 0
                .Pattern = xlSolid
                End With
                Else
             If Cells(k, l) < 0 And Cells(k, l) >= -0.5 Then
                With Cells(k, l).Interior
                .ColorIndex = 6
                .Pattern = xlSolid
                End With
             Else
                With Cells(k, l).Interior
                .ColorIndex = 3
                .Pattern = xlSolid
                End With
            End If
            End If
        Next l
   Next k
End Sub
How to proceed from here.
Thanks
Kiran

Similar Messages

  • Color the cell

    Hello All,
          I have a tableview with contents.
    These contents are summated as  totals and sub-totals in a new row within the tableview.
    Now, I want to color the cell which is summed i.e
    I have 5 records with 10 columns.
    at every new 1 st column the totals are done to the column 3.
    Now i want to color the summated value of the column 3,
    not the whole column.
    Is it possible ?
    I so can anyone guide me ?
    Regards,
    Deepu.K

    Hi Deepu,
    you might have to use the HTML tags to get the required color for the cell.
    E.g - when appending amount total into the internal table - first move that amount into a character type and then append it with color tag of the classic HTML
    something like this...
    "<span style="color:blue;">100.00</span>" - instead of appending just the amount you will need to append the amount along with HTML color tag. This might work for you..
    Cheers

  • How can I merge the cells of excel with using DOI technique?????

    Hello,everybody
    I met a quesetion.
    Now I'm impoving the performance of one program which is used to output data into the excel file.
    Old program used OLE technique, so it runned a very very long time.
    Now I want to change it by using the DOI technique.But I don't know how to merge the excel's cells with
    this technique(DOI).
    Can somebody give me some useful advices?
    I will deeply appreciate for your help.
    Chen

    Hi JUNHUA,
    Check with the [merge cell in DOI|merge cell in DOI ?]
    hope it helps you.
    Regards!

  • How can I put a background image into the cell of a table using Dreamweaver CC.

    I want to place an image in a table cell and then be able to place editable HTML in the same cell on top of image. I also have Dreamweaver CS6. I can't get either one to do it using solution I found searching on web. Please help ASAP. What am I doing wrong. Example code would be great. Thanks!

    No tables required for any of this.  You simply need a 3-column starter page. 
    In DW, go to File > New > Blank page > HTML. 
    Select a 3-column layout from the 3rd panel.
    Hit Create button.
    Learn to use CSS floats, margins and padding to align elements.  DO NOT use positioning.
    Start with & bookmark these links for future reference:
    CSS Box Model
    http://css-tricks.com/all-about-floats/
    CSS Float
    Floatutorial: Step by step CSS float tutorial
    CSS Margin
    CSS Padding
    Nancy O.

  • To color selected cells in dynamically created table in ALV.

    Hi,
           The requirement is to display a table (whose columns are dynamic) using ALV n to color few cells of the table based on some condition.
    For creating the table dynamically i have used the method cl_alv_table_create=>create_dynamic_table.
    Now for coloring the cells i tried to use the field EMPHASIZE .
    But when I try this method the whole column is getting colored.
    So any suggestions on how to color only particular cells.

    Hi,
    Try this one...
    DATA: gs_layout TYPE slis_layout_alv, "Define layout
    gt_color TYPE lvc_t_scol WITH HEADER LINE. "Define Internal Table for Cell Colouring
    Use below Sample Code after building a Field Catalog:
    gs_layout-coltab_fieldname = 'COLINFO'.
    " 'it' is the final internal table which contain positive & negative value of Field 'MENGE'
    LOOP AT it.
    REFRESH gt_color.
    CLEAR gt_color.
    IF it-menge GE 0.
    CLEAR gt_color.
    gt_color-fname = 'MENGE'.
    gt_color-color-col = cl_gui_resources=>list_col_positive.
    gt_color-color-int = 0.
    APPEND gt_color.
    ELSEIF it-menge LE 0.
    CLEAR gt_color.
    gt_color-fname = 'MENGE'.
    gt_color-color-col = cl_gui_resources=>list_col_negative.
    gt_color-color-int = 0.
    APPEND gt_color.
    ENDIF.
    it-colinfo[] = gt_color[].
    MODIFY it.
    ENDLOOP.
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
    i_callback_program = g_repid
    is_layout = gs_layout
    it_fieldcat = ct_fieldcat
    i_save = 'A'
    TABLES
    t_outtab = it
    EXCEPTIONS
    program_error = 1
    OTHERS = 2.
    Hope this solves your problem.
    Regards,
    Tarun

  • Color table cells depending on value of entry in row (UI5 & JSON)

    Hello all,
    I've stuck here a bit. There have been some discussions about how to color the cells of a table that has been bound to a JSON data model. I found some answers how to color individual cells (http://http://scn.sap.com/thread/3383698), but I have a hard time to fulfill the following requirement (rephrased for simplicity):
    Given value "a" in the first cell of a table row, color the row cells 1 - 4 in blue, and 5-7 in red.
    Given value "b" in the first cell of a table row, color the row cells 1 - 4 in yellow and 5-7 in green.
    This wouldn't be a problem with normal HTML as I could easily assign style classes to every cell, however I can't find the solution for the UI5 table.
    Any ideas?
    Thanks,
    Christian

    Hi Nishant,
    not sure if I undestand you correctly.
    When I scroll the table, the data scrolls with the table correctly, but in the "Last Name" column the formatting gets messed up.
    To solve this, you need to remove the previously added classes:
      // Approach 2
        template = new sap.ui.commons.TextView().bindProperty("text", {
                parts: [
                    {path: "***" },
                    {path: "lname" }
                formatter: function(***, lname){
                   // Remove previously added classes
                  this.removeStyleClass("cyan").removeStyleClass("yellow");
                  if(*** == "m" ){
                    <!-- approach 2 step B : Add Css style class to element -->
                    this.addStyleClass("yellow");
                  }  else  if(*** == "f" )
                       this.addStyleClass("cyan");
                  return lname ;
        oTable.addColumn(new sap.ui.table.Column({ label: "Last Name",
                template: template,
    Same for the first approach using where you have to remove the custom data instead if the class.
    This should solve the problem. (By the way this is already mentioned in this thread in my post from Mar 10, 2014 11:40 AM)
    Greeets,
    ben

  • What is the cell definition

    Hi all,
    What is the cell definition option in query designer and what is the use of that ?
    Regards
    Kiran Kumar

    Hi Kiran,
    I believe you are talking about 'Cell Editor' in the Query Designer. If so, let me provide few excerpts from Peter Jones book.
    1) "A cell is an intersection of two structures in a query definition"
    2) it is the 13th icon on your Query Designer (in BI7.0)
    3) "In certain situations where you need to define each specific cell of a query, you may need to use the Cell Editor. For ex, suppose you are looking to create a query that has the divisionslisted in a particular manner and you want to hold all the divisions in the list, even though there are months where certain divisions don't have any sales or data. This may be the reason for using the Cell Editor. The Cell Editor allows you to directly define specific cells in the query via the Query Designer. If you define selection criteria and formulas for structural components and there are structural components of the query, generic cell definitions are created at the intersection of the structural components that determine the valuesto be presented in the cells. Cell-specific definitions allow you to define explicit formulas and selection conditions for cells as well as implicit cell definiitons. This means you can override cell values. This function allows you to design much more detailed queries. In addition, you can define cells that have no direct relationship to the structural components (virtual key figures). These cells are not displayed and serve as containers for help selections or help formulas.
    4) The pre-requisite for this is that the query must have two structures.
    5) "A new cell reference is a cell you have defined that can be reused in a formula. If you want to re-use the value from the implicit, generic cell definition that is automatically created at the intersection of the two structural components of a query, select this cell in the Cell screen area and , using the secondary mouse button, choose New Cell Reference."
    6) "You can also change the properties of a defined cell by selecting it. I nthe properties screen, you can change the description as well"
    I hope this will be helpful.

  • JTable not getting latest data (unless mouse is focussed out of the cell)

    Hi,
    I am using JDK 1.4.2. I am having a basic problem of reading the data present in a JTable.
    JTable table = new JTable(9, 9);
    JButton solveButton = new JButton("Solve");
    solveButton.addActionListener(new DumpListener(table));The dump listener just dumps the data in the table.
    I have a 6*6 jtable where each value is a number. Now i focus the mouse on say square (1,2) and enter some data, then on square (5,5) and enter data say "4". There is a button in this panel, and which on being clicked, gets the table data and does some operation on it.
    Problem is when i use the "getValueAt" API, it gives correct data for square(1,2) but not for (5,5). This is because the mouse focus is still on square (5,5). However if i focus out of square (5,5) using my mouse (to some other random square) then the data comes up properly. Am i missing something here?
    I understand it is to do with the data model getting altered only when the mouse if focussed out? But this seems to be very trivial. Is there a way of getting the data out without focusing the mouse out of the cell?

    My solution uses a JFrame instead of a JApplet.
    But I think the effect is the same.
    First of all, the setVisible(true) should be put after all components are added.
    Secondly, when you retrieve data in the table, you'd synchronized() the model.
    Thirdly, I didn't find any problem when I call stopCellEditing(). Perhaps I'm using Java 5. Anyway, please try whether the following code works.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.table.TableModel;
    public class DummyFrame extends JFrame {
         public static void main(String[] args) {
              SwingUtilities.invokeLater(new Runnable() {
                   public void run() {
                        DummyFrame frame = new DummyFrame();
                        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                        frame.pack();
                        frame.setVisible(true);
         public DummyFrame() {
              JTable table = new JTable(9, 9);
              JButton data = new JButton("DATA");
              data.addActionListener(new SimpleButtonListener(table));
              JPanel panel = new JPanel();
              panel.setLayout(new BorderLayout());
              panel.add(table, BorderLayout.CENTER);
              panel.add(data, BorderLayout.SOUTH);
              getContentPane().setLayout(new BorderLayout());
              getContentPane().add(panel);
    class SimpleButtonListener implements ActionListener {
         JTable table;
         public SimpleButtonListener(JTable table) {
              this.table = table;
         public void actionPerformed(ActionEvent e) {
              synchronized (table) {
                   if (table.isEditing()) {
                        System.out.println("Is Editing!");
                        table.getCellEditor(table.getEditingRow(), table.getEditingColumn()).stopCellEditing();
              printArray(getData());
         String[][] getData() {
              synchronized (table) {
                   TableModel model = table.getModel();
                   synchronized (model) {
                        String[][] question = new String[9][9];
                        for (int i = 0; i < 9; i++) {
                             for (int j = 0; j < 9; j++) {
                                  question[i][j] = model.getValueAt(i,j) == null ? null : model.getValueAt(i,j).toString();
                        return question;
         void printArray(String[][] question) {
              int rows = question.length, columns = question[0].length;
              for (int i = 0; i < rows; i++) {
                   for (int j = 0; j < columns; j++) {
                        System.out.println("[" + i + ", " + j + "] -> "
                                  + question[i][j]);
    }And ... please don't forget to give me the 5 Duke dollars if it works.
    Thank you!
    Asuka Kenji (UserID = 289)
    (Duke Dollars Hunting now ...)

  • See this post to see how to ID the cell tower to which you are connected

    This free Android APP will locate the cell tower you are using.
    https://community.verizonwireless.com/thread/766309
    JerryF

    Hi,
    Thank you for your post here.
    As far as I know, TMG has no option for us to do that. You may capture the packets and distinguish them based on IP.
    Best Regards
    Quan Gu 

  • Using "calc' function to show if the cell is editable(EVDRE Reports)

    Hello All,
    I have a question regarding using the "calc' property in my dimension 'ACCOUNT' in a EvDRE report to display the rows as calculated or input ready cells. I have developed an input template by opening a blank workbook and typing in EVDRE(). I have listed ACCOUNT to be in the rows and Time in the columns. I have listed the memberset to be members in the ACCOUNT and SELF, DEP in the Time dimension. Whenever I expand the EVDRE, I always get the cells to be 'yellow' in color similiar to the calc format. How do I differentiate between the Calculated cell and the input cell. I was thinking to use the CALC functionality similiar to the reports/input schedules written using EVGTS/EVSND functions.
    Any help is appreciated.
    Thanks.

    Hi  bpc4livin,
    Take note that even though you have specified the base members as memberset in your EVDRE, still you must have base level members in your Current View in the Action pane. Remember that each data cells in an EVDRE template is an intersection of the dimension in your rows and columns plus the rest of the dimensions in your application which would come in your current view if you don't define them as memberset. So as long as there is one calculated member in your current view still the cell would be marked as calculated.
    You can use EVDRE's format range to format a scpecific cell or group of cells. To activate this after you typed the EVDRE and refresh the sheet, you must check the allow formatting option in the EVDRE builder that appears. I think that there is already a default format in the format range that says that if a data cell is calculated it would be colored yellow. So if you want further knowldege on how to use the format range, you could see the Using Reports Help in the See Also section of the action pane of the BPC Excel.
    Hope this helps,
    MVS

  • How to set colors in cells depending the conditions  in alvtree

    Hi All,
    Could you please provide me idea or sample program how to set colors in cells depending the conditions  in alvtree.
    Thanks,
    Suresh

    When running vim in a terminal, it will use whatever colour scheme is defined by the terminal.  You should have a look at this thread:
    http://bbs.archlinux.org/viewtopic.php?id=51818
    Also, check the wiki article on Xdefaults.

  • Macro to Unlock the Cell on the start day of the Fiscal period

    Dear Experts
    We are using  fiscal periods for the forecasting.1 period = 15 days.We forecast for 24 fiscal periods.
    We only give chance to some customers to update forecast on  1 day of the fiscal period in the customer planning book .In this regard we have to lock the cell all most all the days except on 1 st day of the fiscal period.If the first of the Fiscal period is Sunday or Saturday, system should not unlock.
    We did not maintained any Time stream ID to the storage bucket profile.
    Example:
    KF1 is used by our customers to update forecast.This keyfigure should always in the unedit mode.On the first day of the Fiscal period system should unlock the keyfigure.If first day of the period is saturday or sunday then system should not unlock this keyfigure.
    Can we use calender in Macro?
    Is it possible to achieve above logic in our case since we did not maintained time stream ID in storage bucket profile.
    Please give your expertise opinion on my requirment.
    regards
    Vicky

    Hi Vicky,
    Whilst other simpler  options are given by others for locking /unlocking a KF with macros, Work around as below,  if feasible in your environment.
    Create two planning books (or with authorization at data view level, 2 data views).
    One planning book PB1 with the KF1 in  non-edit mode. This will be used normally.
    Other planning book PB2 with KF1 in edit mode.
    Create one more authorization profile/ role   for each customer user.
    Assign this additional authorization profile/ role only on specific dates as per background job to give additional authorizations.
    Otherwise, if  no. of user licenses is not an issue, then create an additional user id for each of the customer with additional authorizations and unlock these additional user accounts only on specific dates by background jobs.
    We had in one project, some additional user accounts for similar( not exactly same) requirement. This gave better traceability.
    Regards
    Datta

  • Rules applied to multiple cells trigger color changes when any of the cells

    "Rules applied to multiple cells trigger color changes when any of the cells meet the rule’s condition." That's what Help says, but when I follow the directions, it doesn't work. This is in Numbers 08.
    I have a table where the contents of one column are either "YES" or "NO", depending on formulas using variables from other cells. If YES, I want the fill of that cell and that of two adjacent cells to change from white to green. I select all three cells and use conditional format rules for "text contains:" YES, then choose my fill color. When I return to the table and introduce values for the variables that trigger the rule, only the cell in the YES/NO column changes to green; the other two remain white.
    While I am spreadsheet challenged, I usually can follow directions as plain as those in Help, but it's not working. I couldn't find anything in the discussions after an hour of searching. Is this a known problem or am I just stupid?

    For what it's worth, that's the way I read that line in the User Guide as well. What it actually appears to mean, though is 'Rules applied to multiple cells apply independently to each of the cells."
    Here's a workaround for your three adjacent columns. Long, but fairly simple steps.
    Add a second table to the sheet (Table 2).
    Resize the second table to one column wide and as many rows as you want to apply the conditional format to.
    Set the width of the column to the same width as the three columns you want to highlight, and the row height(s) to match the rows.
    Format to table to have NO Header or Footer row or column.
    Use the Wrap Inspector to uncheck "Object causes wrap"
    In the first top cell of Table 2, enter an = sign, then Click on Table 1 in the sidebar, Click on the first cell that will hold YES or NO.
    Fill the formula down the rest of Table 2.
    With all cells in Table 2 selected, use the Cell Format inspector to set the 'text contains yes' rule and the conditional fill colour for these cells.
    Test the conditional formating by introducing values into Table 1.
    Click on Table 1 in the sidebar, then use the Table inspector to set Cell Fill to 'none'.
    Click on Table 2 in the sidebar, then drag that table onto table 1 aligning it to cover the cells in which the conditional formating is to appear.
    When positioned (and still selected), go to the Arrange menu and Send Backward to move Table 2 behind the (transparent) cells in Table 1.
    With Table 2 still selected, click on the Cell Borders color well and set the Opacity of the borders to 0%.
    Click the Text inspector and set the Text colour Opacity for Table 2 to 0%.
    Regards,
    Barry

  • HELP!! set the cell color in jTable

    I need to set the color of a specific cell in jTable, but, I need to retain the old color in the jTable. It must not reset the whole table.
    would anyone help me in this problem... PLSSSSS its urgent

    A flexible variation on this is to specify formatting options in the JTable's client properties:
    // Use some sort of special "key" to indicate the cell and that you want to set the background color
    String key = "background:" + row + "," + column;
    table.putClientProperty(key, Color.green);You can then write a general table cell renderer that looks for these special formatting options and it doesn't disrupt your existing TableModel in any way:
    public class FormattingTableCellRenderer extends DefaultTableCellRenderer
      public Component getTableCellRendererComponent(JTable table, Object value, int row, int column, ...)
        Component component = super.getTableCellRendererComponent(table, value, row, column, ...);
        // See if the JTable specifies any properties to override the default format
        Color backgroundColor = (Color)table.getClientProperty("background:" + row + "," + column);
        if(backgroundColor != null)
          component.setBackground(backgroundColor);
        return component;
    }Any custom cell renderers you have then simply need to extend FormatTableCellRenderer instead of DefaultTableCellRenderer.
    It's very easy to add formatting options other than background, such as font, to the list of recognised attributes. You'll probably need to make some alterations to get it to recognise selection/focus but hopefully you get the idea.
    Hope this helps.

  • I am in the print mode  but the dimensions I select in the size template do not show up on either the cell size or the photo,  i.e. select 4x6 template lR gives me 3.5x4 8x10 gives me 5.19x3,50 I have to use 8x10 template in order to get 3.5x5.194

    The sizes on the print template do not relate to the size I get in the cell size or on the photo. Template 8x10 gives me 3.5 x5.194 which is on the cell size can't make it any larger. 4X6 template gives me 3.5x4 which is the same as the cell size.  My printer is a new epson 3000 which is set to print 4x6 but LR does not give the 4x6 dimension to the printer just the aforementioned sizes!!!! I have tried everything to get it to print properly to no avail.   The photo system that came with the computer an iMac 27" pro 2013  with yosemite as the os.works fine with he printer!  You just cannot do much other than print with it
    Anybody have any idea what happened?  It used to work fine ____about a week and a half ago
    HELP
    len

    Hi,
    I tried the example and got some weird error messages as follows:
    ********* error messages*********
    ShowComponent.java:90: cannot resolve symbol
    symbol : method getName ()
    location: class javax.swing.UIManager.LookAndFeelInfo[]
    { String plafName = plafs.getName();
    ^
    ShowComponent.java:91: cannot resolve symbol
    symbol : method getClassName ()
    location: class javax.swing.UIManager.LookAndFeelInfo[]
    final String plafClassName = plafs.getClassName();
    ^
    ShowComponent.java:139: cannot resolve symbol
    symbol : method indexOf (char)
    location: class java.lang.String[]
    int equalsPos = args.indexOf('=');
    ^
    ShowComponent.java:143: cannot resolve symbol
    symbol : method forName (java.lang.String[])
    location: class java.lang.Class
    Class componentClass = Class.forName(args);
    ^
    ShowComponent.java:161: cannot resolve symbol
    symbol : method substring (int,int)
    location: class java.lang.String[]
    String name = args.substring(0, equalsPos); //property name
    ^
    ShowComponent.java:162: cannot resolve symbol
    symbol : method substring (int)
    location: class java.lang.String[]
    String value = args.substring(equalsPos+1); //property value
    ^
    6 errors.
    *****end of error messages*****
    I use jdk1.3 and Win2000. Can anybody tell me how to delete above error messages?
    Thanks a lot.
    Li

Maybe you are looking for

  • Help with sound to LCD TV when using HDMI

    I would love any assistance with a problem I am having. I have a new mac mini with a 40" Proscan LCD. I am using a mini-DVI to HDMI adapter and am getting great video - 1080. My issue is that via Keynote I need to get sound to the LCD TV. It is comin

  • ITunes stops working when trying to play purchased video

    Hey Everyone, For some reason whenever I try to play a video or TV program that I purchased from the iTunes store it causes iTunes to shut down and it won't play the video. It does bring up the player for a few seconds then just hangs and a few secon

  • Third party payload installer Adobe_Lightroom_x64.msi failed with exit code: 1603

    Exit Code: 7 Please see specific errors below for troubleshooting. For example,  ERROR: -------------------------------------- Summary -------------------------------------- - 0 fatal error(s), 3 error(s) ----------- Payload: Adobe Photoshop Lightroo

  • Double movies created in IDVD???

    Hi, I just tried the one step IDVD and created a number of DVDs via camcorder. Each completed DVD has two copies of the movie on it. I don't know why or how this happened. Any ideas? TIA Jerry (a MAC newbie)

  • Why is my battery not staying charged while staying plugged in?

    Hello, I  have a HP 2000-0369WM  laptop purchased a year ago (refurbished). For the most part, I always stay plugged in while I use it. For some reason the battery is showing as only 46% charged. I went to Microsoft Community and went through a lot o