Consulting

Results 1 to 2 of 2

Thread: Naming a Range (VBA)

  1. #1
    VBAX Contributor
    Joined
    Nov 2015
    Location
    Minnesota
    Posts
    101
    Location

    Naming a Range (VBA)

    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

  2. #2
    VBAX Contributor
    Joined
    Nov 2015
    Location
    Minnesota
    Posts
    101
    Location
    You know what, I wasn't thinking. I just have to put the two naming lines in the loop. #solved

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •