Sunday, February 13, 2011

Macro: Repetitive Replacing of Table Cells


Here is today's time saver:

I had some tables (actually 1000 pages of tables!) where I needed to replace cells containing various text (denoted by comments from the SME) with a standard word (which was Reserved in this case). Normally, I would triple-click in the cell and then control-v to paste in the text (5 clicks/keys), but there were too many places that I needed to make this change.

Using the following macro this task was reduced to two clicks, once in the cell and then once on the button for the macro. There was one other requirement for this macro, which was that if the cell was in bold, it received slightly different text.

Sub makeCellReserved()
   Selection.SelectCell

   If Selection.Range.Bold = True Then
       Selection.Text = "RESERVED"
   Else
       Selection.Text = "Reserved"
   End If
End Sub

No comments:

Post a Comment