|
|
Subject:
Word 97 Macro Needed!!!
Category: Computers > Software Asked by: google_maniac-ga List Price: $10.00 |
Posted:
14 Feb 2006 14:20 PST
Expires: 16 Mar 2006 14:20 PST Question ID: 445797 |
I need a macro that will enter dashes into the highlighted portion of a table...if it is possible it would be even better if this macro enters dashes only into the empty cells in a highlighted portion of a table. Thanks. |
|
Subject:
Re: Word 97 Macro Needed!!!
Answered By: hammer-ga on 16 Feb 2006 12:55 PST |
Google_Maniac, The following VBA will enter a dash in any empty table cell in the current selection. It loops through each cell in the current selection, checks each one for emptiness, and sets the value of any empty cell to a dash. Sub DoIt() Dim obj As Cell For Each obj In Selection.Cells If obj.Range.Text = Chr(13) & Chr(7) Then obj.Range.Text = "-" End If Next obj End Sub The trick is in knowing how to check if the cell is empty. An "empty" table cell in Word actually has a couple of ASCII characters in it - a 13 and a 7. See the link below under Additional Information for more methods of testing this condition. Good luck with your Word project! - Hammer Search Strategy --------------- word table vba cell empty Additional information ---------------------- Microsoft Word MVP FAQ Site Detect whether a table cell is empty http://word.mvps.org/FAQs/MacrosVBA/TableCellEmpty.htm | |
| |
|
|
Subject:
Re: Word 97 Macro Needed!!!
From: crythias-ga on 15 Feb 2006 18:44 PST |
You sure that's Word and not Excel? |
Subject:
Re: Word 97 Macro Needed!!!
From: google_maniac-ga on 17 Feb 2006 13:13 PST |
EXCELLENT...it works like a charm...however I am requesting one additional thing...which I will add a tip of $5.00 for...I would also like the macro to add a dash if a cell value is found to equal 0. So if the cell has the values "0" or "0.0" or "0.00" it will replace all those with a single dash. Thanks. |
Subject:
Re: Word 97 Macro Needed!!!
From: brix24-ga on 19 Feb 2006 17:07 PST |
Google_maniac, you might try adding your Comment as a "Request for clarification." I think that will send the google researcher an alert that you have this additional request. Otherwise, an answer may depend on whether or not hammer-ga looks at this question again. |
Subject:
Re: Word 97 Macro Needed!!!
From: brix24-ga on 24 Feb 2006 07:59 PST |
google_maniac, I may have been mistaken in believing that a Request for Clarification sent an alert to the researcher. In a partial attempt to redeem myself, I tried to find the answer for you. The best that I have been able to come up with is a macro that replaces exact text, but does not evaluate a cell's value. (Searching led me to a ".Calculate" function, but I got erratic results with that in Excel on a Mac.) Below is a simple modification of hammer-ga's macro. Note: I am not an expert in VBA and do not routinely use word macros, so I would check the results of this macro carefully. I was helped by search results that indicated that the Chr(13) and Chr(7) were used in all Word cells. The macro replaces cells with 0, 0.0, and 0.00; it does not affect cells with "0", .0, or 0.0<space>. This first version is combined with the empty cell replacement action: Sub DoIt() Dim obj As Cell For Each obj In Selection.Cells If (obj.Range.Text = Chr(13) & Chr(7)) Or _ (obj.Range.Text = "0" & Chr(13) & Chr(7)) Or _ (obj.Range.Text = "0.0" & Chr(13) & Chr(7)) Or _ (obj.Range.Text = "0.00" & Chr(13) & Chr(7)) Then obj.Range.Text = "-" End If Next obj End Sub You may prefer to run the replacements for empty cells and for zero value cells separately since this makes it easy to visually check the results for possible malfunctions. (Note: in testing the macros, I found that, in Excel on a Mac, if I created a table and used "select all," not everything got replaced; however, if I decreased the selection to include just the cells in the table, the macros worked fine. There may be other situation that you will have to be on the alert for.) Sub DoItZero() Dim obj As Cell For Each obj In Selection.Cells If (obj.Range.Text = "0" & Chr(13) & Chr(7)) Or _ (obj.Range.Text = "0.0" & Chr(13) & Chr(7)) Or _ (obj.Range.Text = "0.00" & Chr(13) & Chr(7)) Then obj.Range.Text = "-" End If Next obj End Sub |
If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you. |
Search Google Answers for |
Google Home - Answers FAQ - Terms of Service - Privacy Policy |