Excel VBA (Macro)Sample Programming Codes

Macro for deleting cell contents

 

Sometimes you need to plot a graph that does not show data when a specific condition applies. For instance, in the process of liquefaction triggering analysis you may want to plot a graph that shows the variation of fines content for depths with Ic less than 2.6. You may try the options below without using VBA macro:

  • Assign this formula for a column; “=if(row_i_column_Ic > 2.6, ” “, row_i_column_FC)”: In this case Excel would assign string type data for the cells and because of that the graph would look odd as shown in Figure 1a below.
  • Assign this formula for a column; “=if(row_i_column_Ic > 2.6, 0.0, row_i_column_FC)”: In this case the graph would show zeros which is not really what you like to illustrate. See Figure 1b below.

In order to resolve this issue, you can incorporate the macro below into your spreadsheet. See Figure 1c below for results. The code is very simple, straightforward, and efficient. Click here to download:  delete-cell-contents-Macro.zip

Figure 1. Application of the developed Macro in presenting results.

Leave a Reply

Your email address will not be published. Required fields are marked *