Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 42
Default Use of Range Property

I am trying to tighten up some old code that used a loop to change blank
cells to 0.
I want to use the following code but it doesn't work.

Range("A2").Select

Set MyRange = ActiveCell.CurrentRegion

MyRange.Select

Range(MyRange).SpecialCells(xlCellTypeBlanks) = "0" ' this does not work
' old code had a loop structure here using MyRange and it works but is slow

if I use [Range(a1:aq237).SpecialCells(xlCellTypeBlanks) = "0"] then it
works fine, any ideas.
thanx
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Use of Range Property

Arnold,

Replace everything you have with

Range("A2").CurrentRegion.SpecialCells(xlCellTypeB lanks).Value = "0"

or

Range("A2").CurrentRegion.SpecialCells(xlCellTypeB lanks).Value = 0

HTH,
Bernie
MS Excel MVP


"Arnold Klapheck" wrote in message
...
I am trying to tighten up some old code that used a loop to change blank
cells to 0.
I want to use the following code but it doesn't work.

Range("A2").Select

Set MyRange = ActiveCell.CurrentRegion

MyRange.Select

Range(MyRange).SpecialCells(xlCellTypeBlanks) = "0" ' this does not work
' old code had a loop structure here using MyRange and it works but is slow

if I use [Range(a1:aq237).SpecialCells(xlCellTypeBlanks) = "0"] then it
works fine, any ideas.
thanx



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Use of Range Property

Hi Arnold

Use it like this

Set MyRange = ActiveCell.CurrentRegion
MyRange.SpecialCells(xlCellTypeBlanks).Value = "0" '


--
Regards Ron de Bruin
http://www.rondebruin.nl



"Arnold Klapheck" wrote in message
...
I am trying to tighten up some old code that used a loop to change blank
cells to 0.
I want to use the following code but it doesn't work.

Range("A2").Select

Set MyRange = ActiveCell.CurrentRegion

MyRange.Select

Range(MyRange).SpecialCells(xlCellTypeBlanks) = "0" ' this does not work
' old code had a loop structure here using MyRange and it works but is slow

if I use [Range(a1:aq237).SpecialCells(xlCellTypeBlanks) = "0"] then it
works fine, any ideas.
thanx



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 42
Default Use of Range Property

This seems to be working (changing blanks to 0) but it is going into my
Errorhandler and returning 0: any idea why it is
returning an error? should I just take the errorhandler out?

Sub Zero_Fill_In()
On Error GoTo Errorhandler
Application.ScreenUpdating = False
Range("A2").CurrentRegion.SpecialCells(xlCellTypeB lanks).Value = 0
' also tried it with "0", does same thing
Errorhandler:
Dim Msg As String
Msg = Err.Number & ":" & Err.Description
MsgBox Msg

End Sub

"Bernie Deitrick" wrote:

Arnold,

Replace everything you have with

Range("A2").CurrentRegion.SpecialCells(xlCellTypeB lanks).Value = "0"

or

Range("A2").CurrentRegion.SpecialCells(xlCellTypeB lanks).Value = 0

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Use of Range Property

Arnold,

You need to put

Exit Sub

as the last line before your error handler, for cases when you don't have an error.

HTH,
Bernie
MS Excel MVP


"Arnold Klapheck" wrote in message
...
This seems to be working (changing blanks to 0) but it is going into my
Errorhandler and returning 0: any idea why it is
returning an error? should I just take the errorhandler out?

Sub Zero_Fill_In()
On Error GoTo Errorhandler
Application.ScreenUpdating = False
Range("A2").CurrentRegion.SpecialCells(xlCellTypeB lanks).Value = 0
' also tried it with "0", does same thing
Errorhandler:
Dim Msg As String
Msg = Err.Number & ":" & Err.Description
MsgBox Msg

End Sub

"Bernie Deitrick" wrote:

Arnold,

Replace everything you have with

Range("A2").CurrentRegion.SpecialCells(xlCellTypeB lanks).Value = "0"

or

Range("A2").CurrentRegion.SpecialCells(xlCellTypeB lanks).Value = 0





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Use of Range Property

specialcells raises an error if there are no blank cells in the range

Use this for illustration

Sub FillZeros()
Dim rng as Range, rng1 as Range
set rng = Range("A2").currentRegion
if rng.count = 1 then
if isempty(rng) then
rng.value = 0
end if
else
on Error Resume Next
set rng1 = rng.SpecialCells(xlBlanks)
On error goto 0
if rng1 is nothing then
msgbox "No blank cells in " & rng.address
else
rng1.Value = 0
end if
end if
End sub

--
Regards,
Tom Ogilvy


"Arnold Klapheck" wrote:

This seems to be working (changing blanks to 0) but it is going into my
Errorhandler and returning 0: any idea why it is
returning an error? should I just take the errorhandler out?

Sub Zero_Fill_In()
On Error GoTo Errorhandler
Application.ScreenUpdating = False
Range("A2").CurrentRegion.SpecialCells(xlCellTypeB lanks).Value = 0
' also tried it with "0", does same thing
Errorhandler:
Dim Msg As String
Msg = Err.Number & ":" & Err.Description
MsgBox Msg

End Sub

"Bernie Deitrick" wrote:

Arnold,

Replace everything you have with

Range("A2").CurrentRegion.SpecialCells(xlCellTypeB lanks).Value = "0"

or

Range("A2").CurrentRegion.SpecialCells(xlCellTypeB lanks).Value = 0

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
VBA Range Property AndrewCrisp[_2_] Excel Programming 3 July 23rd 06 09:27 PM
range property of range object Woody[_3_] Excel Programming 1 June 23rd 05 09:04 PM
Row and Column from Used Range property?? C. Johnson Excel Programming 1 March 31st 05 07:51 PM
Range Resize property jacqui[_2_] Excel Programming 7 February 24th 04 06:11 PM
using a range with isnumber property chick-racer[_33_] Excel Programming 2 November 12th 03 06:53 PM


All times are GMT +1. The time now is 04:12 AM.

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"