Consulting

Results 1 to 5 of 5

Thread: Solved: Looping named cells

  1. #1
    VBAX Regular
    Joined
    Apr 2010
    Posts
    32
    Location

    Solved: Looping named cells

    I have a worksheet with some named cells, ie. cells a2, a3, a4 have been give the names INJ1, INJ2, INJ3.

    Is it possible to loop through these cells to check that they have a value in them?

    FYI, what i mean by saying i've named the cells is i've selected the cell and done 'Insert -> Name -> Define' from the menu bars.

    Thanks!!

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Dim cell As Range

    For Each cell In Range("INJ1,INJ2,INJ3")

    Debug.Print cell.Address
    Next cell
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Regular
    Joined
    Apr 2010
    Posts
    32
    Location
    Thanks for the reply xld. Is it possible to do a like/left function or do I have to put in the full cell name?

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Has to b e the full cell name I am afraid.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    [VBA]Sub CheckVals()
    Dim Nm, Msg$
    For Each Nm In ActiveWorkbook.Names
    If Nm.Name Like "INJ*" Then
    Msg = Msg & Nm.Name & vbTab & Range(Nm).Value & vbCr
    End If
    Next
    MsgBox Msg
    End Sub
    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

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