例如:
Dim oExcel
Set oExcel = CreateObject("Excel.Application")
oExcel.Visible = 1
oExcel.Workbooks.Add
oExcel.Cells(1,1).Value = "one"
oExcel.Cells(1,2).Value = "two"
用Cells对象的Value来取到值判断:
If oExcel.Cells(1,3)=vbEmpty Then
Msgbox "Empty!"
End If
或者
If oExcel.Cells(1,3)="" Then
Msgbox "空!"
End If作者: yujie6832 时间: 2010-4-6 09:28
楼上正解作者: ecust 时间: 2010-4-6 10:29
可创建一个新的空excel然后做对比.
Function CompareSheets(sheet1, sheet2, startColumn, numberOfColumns, startRow, numberOfRows, trimed) 'As Boolean
Dim returnVal 'As Boolean
returnVal = True
'In case that one of the sheets doesn't exists, don't continue the process
If sheet1 Is Nothing Or sheet2 Is Nothing Then
CompareSheets = False
Exit Function
End If
'loop through the table and fill values into the two worksheets
For r = startRow to (startRow + (numberOfRows - 1))
For c = startColumn to (startColumn + (numberOfColumns - 1))
Value1 = sheet1.Cells(r, c)
Value2 = sheet2.Cells(r, c)
'if 'trimed' equels True then used would like to ignore blank spaces
If trimed Then
Value1 = Trim(Value1)
Value2 = Trim(Value2)
End If
'in case that the values of a cell are not equel in the two worksheets
'create an indicator that the values are not equel and set return value
'to False
If Value1 <> Value2 Then
Dim cell 'As Excel.Range
sheet2.Cells(r, c) = "Compare conflict - Value was '" & Value2 & "', Expected value is '" & Value1 & "'."
Set cell = sheet2.Cells(r, c)
cell.Font.Color = vbRed
returnVal = False
End If
Next
Next
CompareSheets = returnVal
End Function