Results 1 to 3 of 3

Thread: Value of a range of cells in Excel ???

  1. #1

    Thread Starter
    Frenzied Member wengang's Avatar
    Join Date
    Mar 2000
    Location
    Beijing, China
    Posts
    1,604
    Hi all.

    I just need one line for VB. It is just to say if any of the cells in a range have data in them, then.....


    If (Range of Cells).Value <> "" Then.........

    But this isn't right. Is there one line in VBA that means the value of any of the cells?


    Thanks

    Wengang
    Wen Gang, Programmer
    VB6, QB, HTML, ASP, VBScript, Visual C++, Java

  2. #2
    Hyperactive Member
    Join Date
    Jul 2002
    Location
    Canada
    Posts
    455
    Hello wengang,

    Try this source:

    Private Sub Form_Load()
    Dim XLS As Object
    Dim XLSheet As Object

    ' Set the Application (Excel)
    Set XLS = CreateObject("Excel.Application")

    Set XLSheet = XLS.Worksheets("YourSheet")

    If XLSheet.Cells(1, 2) <> "" Then
    End If

    End Sub

    Nice regards,

    Michelle.

  3. #3
    Addicted Member
    Join Date
    Aug 2000
    Posts
    178

    Cool Could Try This

    You could also use this if you wanted a whole range....

    Code:
    Dim Xlobj as object, Xlsheet as object
    Dim IsThisCellEmpty as variant
    
    Set Xlobj = CreateObject("Excel.Application")
    Xlobj.Workbooks.open("C:\MyWorkbook To Check")
    Set Xlsheet = Xlobj.Activeworkbook.Sheets("MySheet To Check")
    
    With Xlsheet
      For Each IsThisCellEmpty In .Range("A2:A9")
          If IsThisCellEmpty.Value <> "" Then
              Debug.Print IsThisCellEmpty.Address & " Isn't Empty and Has The Value " & IsThisCellEmpty.Value
          End If
      Next IsThisCellEmpty
    End With
    Where you can change the range A2:A9 to whatever range you want. Hope this helps

    Cheers
    Steve

Posting Permissions

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



Click Here to Expand Forum to Full Width