Loading
Ozgrid Excel Help & Best Practices Forums

Excel Video Tutorials / Excel Dashboards Reports



Results 1 to 6 of 6

Thread: how to read a value from a cell in VBA?

  1. #1
    Join Date
    31st March 2003
    Posts
    27
    how to read a value from a cell in VBA?

    Excel Video Tutorials / Excel Dashboards Reports


  2. #2
    Join Date
    24th January 2003
    Location
    Australia
    Posts
    31,716
    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

  3. #3
    Join Date
    7th March 2003
    Location
    Essex, England
    Posts
    11,310
    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

    Excel Video Tutorials / Excel Dashboards Reports


  4. #4
    Join Date
    31st March 2003
    Posts
    27
    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?

    Excel Video Tutorials / Excel Dashboards Reports


  5. #5
    Join Date
    24th January 2003
    Location
    Australia
    Posts
    31,716
    Hi Peach

    Try using



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

  6. #6
    Join Date
    31st March 2003
    Posts
    27
    Thanks!

    Excel Video Tutorials / Excel Dashboards Reports


Thread Information

Users Browsing this Thread

There are currently 5 users browsing this thread. (0 members and 5 guests)

Possible Answers

  1. Read Workbook, Worksheet & Cell Address From Cell
    By MikeBrough in forum EXCEL HELP
    Replies: 4
    Last Post: September 21st, 2007, 01:03
  2. use vb read cell
    By castel in forum EXCEL HELP
    Replies: 3
    Last Post: January 13th, 2006, 16:08
  3. Read A Cell In Wbook...
    By sal21 in forum EXCEL HELP
    Replies: 3
    Last Post: June 22nd, 2004, 07:04
  4. cannot read from cell
    By sreerajks in forum EXCEL HELP
    Replies: 1
    Last Post: January 28th, 2004, 14:12
  5. Read data in cell
    By Rava in forum EXCEL HELP
    Replies: 3
    Last Post: February 16th, 2003, 19:24

Bookmarks

Posting Permissions

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