Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
ME ME is offline
external usenet poster
 
Posts: 3
Default Macro and a range of cells

Hi All,

I have a macro which replaces zeros with "-".
I would like to use the macro in any range
of cells but I don't know how to do it.
Despite I set any range of cells, the macro
always changes zeros into "-" in entire sheet.

I'd be very grateful for your help.

Regards
ME

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,058
Default Macro and a range of cells

Sub dash_it()
For Each r In Selection
If Not IsEmpty(r) And r.Value = 0 Then
r.Value = "-"
End If
Next
End Sub


select the cells and run the macro
--
Gary''s Student - gsnu200720


"ME" wrote:

Hi All,

I have a macro which replaces zeros with "-".
I would like to use the macro in any range
of cells but I don't know how to do it.
Despite I set any range of cells, the macro
always changes zeros into "-" in entire sheet.

I'd be very grateful for your help.

Regards
ME


  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 173
Default Macro and a range of cells

Sorry - I misinterpretted the question - blanks are being seen as 0's. Good
thing Gary's Student was watching.
Will

"Gary''s Student" wrote:

Sub dash_it()
For Each r In Selection
If Not IsEmpty(r) And r.Value = 0 Then
r.Value = "-"
End If
Next
End Sub


select the cells and run the macro
--
Gary''s Student - gsnu200720


"ME" wrote:

Hi All,

I have a macro which replaces zeros with "-".
I would like to use the macro in any range
of cells but I don't know how to do it.
Despite I set any range of cells, the macro
always changes zeros into "-" in entire sheet.

I'd be very grateful for your help.

Regards
ME


  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 173
Default Macro and a range of cells

ME
If you selected the range with the cursor before running the macro you could
use something like this:

dim R as Range
for each R in selection
if R.Value=0 then R.value="-"
next R

or if you have a named range (call it "NRange")

dim R as Range
for each R in Range("NRange")
if R.Value=0 then R.Value="-"
next r

Will

"ME" wrote:

Hi All,

I have a macro which replaces zeros with "-".
I would like to use the macro in any range
of cells but I don't know how to do it.
Despite I set any range of cells, the macro
always changes zeros into "-" in entire sheet.

I'd be very grateful for your help.

Regards
ME


  #5   Report Post  
Posted to microsoft.public.excel.misc
ME ME is offline
external usenet poster
 
Posts: 3
Default Macro and a range of cells

Thank you very much. It works.:-)

Regards
ME

Sub dash_it()
For Each r In Selection
If Not IsEmpty(r) And r.Value = 0 Then
r.Value = "-"
End If
Next
End Sub


select the cells and run the macro
--
Gary''s Student - gsnu200720


"ME" wrote:

Hi All,

I have a macro which replaces zeros with "-".
I would like to use the macro in any range
of cells but I don't know how to do it.
Despite I set any range of cells, the macro
always changes zeros into "-" in entire sheet.

I'd be very grateful for your help.

Regards
ME




  #7   Report Post  
Posted to microsoft.public.excel.misc
ME ME is offline
external usenet poster
 
Posts: 3
Default Macro and a range of cells

Will
Your macro works too. Thanks a lot.

Regards
ME

ME
If you selected the range with the cursor before running the macro you could
use something like this:

dim R as Range
for each R in selection
if R.Value=0 then R.value="-"
next R

or if you have a named range (call it "NRange")

dim R as Range
for each R in Range("NRange")
if R.Value=0 then R.Value="-"
next r

Will

"ME" wrote:

Hi All,

I have a macro which replaces zeros with "-".
I would like to use the macro in any range
of cells but I don't know how to do it.
Despite I set any range of cells, the macro
always changes zeros into "-" in entire sheet.

I'd be very grateful for your help.

Regards
ME


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
modify a macro to apply to a specific range of cells Dave F Excel Discussion (Misc queries) 2 April 25th 07 03:00 AM
MACRO HELP - deleting rows containing a range of blank cells DavidHawes Excel Discussion (Misc queries) 9 February 26th 07 03:40 PM
Macro to hide blank cells in a range Dave Excel Discussion (Misc queries) 1 February 1st 06 11:55 PM
Macro €“ select all cells in current range Mary Ann Excel Discussion (Misc queries) 3 December 12th 05 07:19 AM
Running a macro if any data is entered in a range of cells Jonathan Excel Worksheet Functions 3 November 16th 05 08:38 PM


All times are GMT +1. The time now is 02:14 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"