Selecting more than 1 named range

D

Diddy

Hi,

I'm trying to add zeroes to blank cells in ranges to make them contiguous.

I have named the ranges and used the macro recorder to select the range
which gives me

Application.Goto Reference:="MyRange1"
On Error Resume Next
Selection.SpecialCells(xlBlanks).Value = 0
On Error GoTo 0

This works fine, but how can I alter it to select a number of non-contiguous
at the same time.

Could anyone also explain the difference between Select and the
Application.Goto Reference please.

Many thanks
 
G

Gary''s Student

This assumes that the Names have already been assign in the worksheet:

Sub zeroThem()
Set r = Union(Range("myRange1"), Range("myRange2"))
On Error Resume Next
r.SpecialCells(xlBlanks).Value = 0
On Error GoTo 0
End Sub

You do not need to either GoTo the cells or Select the cells.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top