Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Concatenating ranges 1

Status
Not open for further replies.

bultimatem

Programmer
Jun 9, 2003
13
US
I have a named range of rows (say, rows C:G) and I want to take it and add row A to it so that the range now covers rows A,C,D,E,F,G. Any ideas on how to do this in VBA?
Thanks,

Bryan Marble
IEWS
BAE Systems
 
Look in the Excel VBA help file with index entry "Union" and select "Referring to multiple ranges"

You can combine multiple ranges into one Range object using the Union method. The following example creates a Range object called myMultipleRange, defines it as the ranges A1:B2 and C3:D4, and then formats the combined ranges as bold.
Code:
Sub MultipleRange()
	Dim r1, r2, myMultipleRange As Range
	Set r1 = Sheets("Sheet1").Range("A1:B2")
	Set r2 = Sheets("Sheet1").Range("C3:D4")
	Set myMultipleRange = Union(r1, r2)
	myMultipleRange.Font.Bold = True
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top