Excel Macro to Add Border to Cells in Rows Based on Criteria in Column

  • I need a looping macro to add borders to cells in a row if the value in column A is greater than zero. I have searched but have not found anything close to what I need. The border should be a thin line and cover each cell in that row up to column L. Please advise. Thanks.

  • Re: Excel Macro to Add Border to Cells in Rows Based on Criteria in Column


    I dont think you need a looping macro at all (but I havent seen your spreadsheet). Sounds to me like conditional formatting would do the trick nicely. Format each cell in the row up to row "L" for a condition based on a formula. Start on row 1... Highlight all the cells from A1 to L1. Go to conditional formatting... format the cells based on a formula. The formula should be =$A1>0 .


    If you want to start your formatting on row 10... the conditional formatting formula would be =$A10>0 etc.


    Copy/pastespecial the formatting for all other rows.


    Welcome to the forum.


    Regards,
    Ger

    _______________________________________________
    There are 10 types of people in the world. Those that understand Binary and those that dont. :P


    Why are Halloween and Christmas the same? Because Oct 31 = Dec 25... ;)

    _______________________________________________

  • Re: Excel Macro to Add Border to Cells in Rows Based on Criteria in Column


    Thanks. Would you be able to provide some sample code? I am better at manipulating code than starting from scratch. Thanks.

  • Re: Excel Macro to Add Border to Cells in Rows Based on Criteria in Column


    Like I said, there is no code.


    In my sample, select a cell with data Go to "Home" tab, go to conditional formatting icon and Click manage rules. Its a simple formula =$A1>0


    Try googling "Conditional Formatting tutorial". Conditional Formatting is extremely powerful and you should read up on it as it will often get you out of a tight spot and make your spreadsheets look pretty cool and dynamically react without code.


    For example, keep pressing "F9" to recalculate the sheet and see how the border keeps changing based on the values in column A.


    Ger

    Files

    _______________________________________________
    There are 10 types of people in the world. Those that understand Binary and those that dont. :P


    Why are Halloween and Christmas the same? Because Oct 31 = Dec 25... ;)

    _______________________________________________

  • Re: Excel Macro to Add Border to Cells in Rows Based on Criteria in Column


    Thanks. I know how to do that but I need a macro because I need it done on multiple sheets which are dynamic. I have other macros running which are doing other things. It is not always the same amount of rows. I also want it to skip certain rows.

  • Re: Excel Macro to Add Border to Cells in Rows Based on Criteria in Column


    try this


    if you got what you want please mark the thread as closed.

  • Re: Excel Macro to Add Border to Cells in Rows Based on Criteria in Column


    You can do all of what you need / asked for using conditional formatting. Hence my suggestion to get a good tutorial on it, including variable length rows etc. But if you insist in doing this the wrong way (IMHO) this should get you started:



    Ger

    _______________________________________________
    There are 10 types of people in the world. Those that understand Binary and those that dont. :P


    Why are Halloween and Christmas the same? Because Oct 31 = Dec 25... ;)

    _______________________________________________

  • Re: Excel Macro to Add Border to Cells in Rows Based on Criteria in Column


    Thanks. I think you were misunderstanding me. I need something dynamic. I have users pulling in sheets from other workbooks and then formatting them with a macro. I need this done quickly. The formatting done prior to the borders involves inserting rows and deleting certain things. I was trying to automate the process. The sheets change every month. I do not believe conditional formatting would work. The old sheets are deleted out and then new sheets brought in every month. I hope that makes sense.

  • Re: Excel Macro to Add Border to Cells in Rows Based on Criteria in Column


    Quote

    I am better at manipulating code than starting from scratch


    OK, well two of us have provided similar type code to get you started. ;)


    Cheers
    Ger

    _______________________________________________
    There are 10 types of people in the world. Those that understand Binary and those that dont. :P


    Why are Halloween and Christmas the same? Because Oct 31 = Dec 25... ;)

    _______________________________________________

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!