Here is a way to update a range that is not contiguous using VBA
Sub NonContiguous_Range_Example()
Dim oRng As Range
Set oRng = Range("A1, B5, C9")
oRng.Value = "45"
oRng.Interior.ColorIndex = 34
End Sub
The output will be as shown below:
Welcome to VBA Tips & Tricks. All VBA related information will be posted on this blog. Of late, VBA has been disregarded by many software professionals for .Net, c# and other technologies. This blog will also post articles related to them too Happy reading
Here is a way to update a range that is not contiguous using VBA
Sub NonContiguous_Range_Example()
Dim oRng As Range
Set oRng = Range("A1, B5, C9")
oRng.Value = "45"
oRng.Interior.ColorIndex = 34
End Sub
The output will be as shown below:
Your picture is the result of
ReplyDeleteRange("A1, B5, C9")
not
Range("A:A, B5, C9")
Many Thanks John. I have corrected it
ReplyDeleteWhat if you want to build a non-contiguous range without hard-coding the addresses?
ReplyDeletewhat is noncontiuos range of cells
ReplyDeleteHow do i select a range non-contiguous range?
ReplyDeleteI have built a range using a union:
this works ok:
Set range_to_select = Union(cell, Range("a1"))
range_to_select.Font.Bold = True
but when I try to select the range, it goes crazy:
Set range_to_select = Union(cell, Range("a1"))
range_to_select.select
am i missing a "cells" somewhere?
Excel add-in user
ReplyDeleteIn both your examples shown "cell" does not represent a range in fact it does not represent anything.
If you wanted a union on say cells(5,10) you could use:
Set range_to_select = Union(cells(5,10), Range("a1"))
range_to_select.Font.Bold = True
and
Set range_to_select = Union(cells(5,10), Range("a1"))
range_to_select.select