PDA

View Full Version : [SOLVED] Naming a Range (VBA)



Nick72310
02-29-2016, 02:38 PM
I am trying to name a range that is being created by my for loop in the given code below. All the code in the loop works, I'm just not sure what the proper syntax is for naming the range.
Thanks for the help!


Sub NAMING()
On Error GoTo ES
Dim i
For i = 1 To 100
Cells(10, 2 + i) = Application.WorksheetFunction.HLookup(2008 + i, [Headers], 1, 0)
Cells(11, 2 + i) = "=IFERROR(Index(Table, $B$11," & 4 + i & "),""0"")" 'Make Formula
Cells(12, 2 + i) = "=IFERROR(Index(Table, $B$12," & 4 + i & "),""0"")" 'Buy Formula
Next i

Range(Cells(11, 3), Cells(11, 2 + i)).Name = "NAME1"
Range(Cells(12, 3), Cells(12, 2 + i)).Name = "NAME2"

ES:
Exit Sub

End Sub

Nick72310
02-29-2016, 02:49 PM
You know what, I wasn't thinking. I just have to put the two naming lines in the loop. #solved