Katy Jordan
Well-known Member
- Joined
- Jun 28, 2008
- Messages
- 596
Hi, can a named range be used inside an array?
So
Worksheets(Wary(a))Array("NamedRange")
So
Worksheets(Wary(a))Array("NamedRange")
Dim wksAry, i As Long
wksAry = Range("NamedRange")
For i = 1 To UBound(wksAry, 1)
With Worksheets(CStr(wksAry(i, 1)))
'do something
End With
Next
Something like..
Code:Dim wksAry, i As Long wksAry = Range("NamedRange") For i = 1 To UBound(wksAry, 1) With Worksheets(CStr(wksAry(i, 1))) 'do something End With Next
With ShtRaw
LR = .Cells(Rows.Count, 1).End(xlUp).Row
.AutoFilterMode = False
With .Range("A5:O" & LR)
For a = LBound(WSary) To UBound(WSary)
.AutoFilter Field:=2, Criteria1:=WSary(a)
NR = Worksheets(WSary(a)).Range("A" & Rows.Count).End(xlUp).Offset(1).Row
'Copy Data to destination worksheets
On Error Resume Next
.Columns("A:C").Offset(1).Resize(.Rows.Count - 1).SpecialCells(12).Copy
Worksheets(WSary(a)).Range("A" & NR).PasteSpecial Paste:=xlPasteValues
.Columns("F:O").Offset(1).Resize(.Rows.Count - 1).SpecialCells(12).Copy
Worksheets(WSary(a)).Range("D" & NR).PasteSpecial Paste:=xlPasteValues
NR = Worksheets(WSary(a)).Range("A" & Rows.Count).End(xlUp).Offset(1).Row
'Apply Formatting
With Worksheets(WSary(a)).Range("A6:M" & NR & ",Q6:R" & NR)
.Borders.LineStyle = xlNone
.Borders.LineStyle = xlContinuous
.Interior.ColorIndex = 0
.Borders.Weight = xlHairline
End With
Do you get any error ? It seems OK to me.
Here's a way to do it without looping:
"shtname" is the name of your named range.Code:Dim vSheet As Variant vSheet = Application.Transpose(Range("shtname"))