Announcement

Collapse
No announcement yet.

how to read a value from a cell in VBA?

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • how to read a value from a cell in VBA?



    how to read a value from a cell in VBA?

  • #2
    Hi Peach

    The default Property of a cell is the Value Property, so

    Sub ReadCell()
    msgbox Range("A1")
    End Sub

    OR

    Sub ReadCell()
    msgbox Range("A1").Value
    End Sub

    Will both read the value of range A1 of the active sheet. If the cell to be read is on another sheet, use

    Sub ReadCell()
    msgbox Sheets("Sheet2").Range("A1").Value
    End Sub

    Comment


    • #3
      Hi peach,

      You could try,

      msgbox "Activecell (" & activecell.address & ") = " & Activecell.value

      or

      msgbox "Cell A1 = " & Range("A1").value

      The first uses the Currently selected cell and the second uses the cell A1 on the current worksheet.

      Hope this helps.

      Cheers
      Andy

      Cheers
      Andy

      Comment


      • #4
        Hi Andy n Dave,

        Thanks for the reply...
        My problem is to have a variable Range.
        I will read the range from 2 cells, that explains my earlier posting.

        Eg. if what i wanted was Range("A82:G88").

        I have cell I82 containing the value of A82 and cell J82 containing the value G88

        Range((Range("I82").Value:Range("J82").Value))

        but I got syntax error.

        what's wrong with my code?

        Comment


        • #5
          Hi Peach

          Try using



          Code:
          Sub TryThis()
          Dim rRange As Range
          Set rRange = Range(Range(Range("I82").Text), Range(Range("J82").Text))
          rRange.Select
          End Sub

          Comment


          • #6


            Thanks!

            Comment

            Working...
            X