Consulting

Results 1 to 2 of 2

Thread: picking range from "A1" to variable

  1. #1

    picking range from "A1" to variable

    Hi guys!
    I'm stuck in a very stupid thing- i'm trying to loop through this range

    For Each c In Worksheets("Sheet1").Range("A1: & LastCell &").Cells

    If c.Value = value1 Then
    value2 = .Cells(c.Row, "B").Value
    MsgBox (value2)
    End If
    Next c


    I have this variable
    LastCell=A17

    And I would like to put it instead of the explicit cell but i keep getting erros- how can I use varible ina a range?

    what is the right syntax for that?

    thanx!

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

    For Each c In Worksheets("Sheet1").Range("A1: & LastCell).Cells

    If c.Value = value1 Then
    value2 = .Cells(c.Row, "B").Value
    MsgBox (value2)
    End If
    Next c
    [/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

Posting Permissions

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