|
-
Sep 4th, 2003, 09:06 AM
#1
Thread Starter
Fanatic Member
When does Excel's Range object's Text property return Null
Was writing a function to determine whether a particular row in an Excel spreadsheet was empty or not. My spreadsheet has 21 columns labled. For me, if the 22nd column contains any text I wouldn't care as long as the other columns contain text. I wanted to detect if all of those 21 columns were empty. Here's my function.
Code:
Public Enum SpreadsheetColumns
EquipmentID = 0
Supplier = 1
Manufacturer = 2
ModelNumber = 3
LocationDept = 4
SerialNumber = 5
AcquisitionTerms = 6
LeaseEndDate = 7
PurchaseDate = 8
PurchasePrice = 9
Depreciation = 10
IsColorDevice = 11
PagesPrintedPerMonth = 12
AmountSupplies = 13
AmountServices = 14
CPPTotal = 15
CPPSupplies = 16
CPPService = 17
NumInvoices = 18
ApplicationData = 21
End Enum
Public Function GetColumnAlphabetFromIndex(ByVal ZeroBasedColumnIndex As SpreadsheetColumns) As String
If ZeroBasedColumnIndex < 0 Or ZeroBasedColumnIndex > 21 Then Exit Function
GetColumnAlphabetFromIndex = Choose _
(ZeroBasedColumnIndex + 1, _
"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V")
End Function
Public Function IsRowEmpty(ByVal RowNumber As Long) As Boolean
Dim StrFromCell As String
Dim StrToCell As String
StrFromCell = GetColumnAlphabetFromIndex(SpreadsheetColumns.EquipmentID) & CStr(RowNumber)
StrToCell = GetColumnAlphabetFromIndex(SpreadsheetColumns.ApplicationData) & CStr(RowNumber)
If IsNull(Sheet1.Range(StrFromCell & ":" & StrToCell).Text) Then
IsRowEmpty = True
Else
IsRowEmpty = Trim(Sheet1.Range(StrFromCell & ":" & StrToCell).Text) = vbNullString
End If
End Function
Why does the line:
Code:
Sheet1.Range(StrFromCell & ":" & StrToCell).Text
return a value Null in my code when I actually have data in the row?
-
Sep 4th, 2003, 11:58 AM
#2
Addicted Member
you could try this
For Each c In Sheet1.Range(StrFromCell & ":" & StrToCell)
If c.Value <> "" Or c.Value <> vbNullString Then
IsRowEmpty = False
Exit For
Else
IsRowEmpty = True
End If
Next
-
Sep 5th, 2003, 06:06 AM
#3
Thread Starter
Fanatic Member
That was what I'd done earlier, but you see, if
returns Null, then VBA won't even evaluate it and will just give up with a bloated Err object. So there's not much you can do to find out if its vbNullString. Besides your check
Code:
c.Value = "" Or c.Value = vbNullString
is more or less redundant.
However, some friends at another forum helped me with three working solutions. I think it was Code Guru or Extreme Visual Basic.
Thanks for your time, friend.
-
Sep 5th, 2003, 07:43 AM
#4
Addicted Member
why dont you post the solution?
-
Sep 5th, 2003, 08:04 AM
#5
Thread Starter
Fanatic Member
-
Sep 5th, 2003, 08:15 AM
#6
Addicted Member
my solution works just as well and if the there is text in cell one it doesnt check anything else
I added is vbnull
because you had it in there
but what a good forum for getting help
I have only just joined and most people are thankfull for us taking the time to look into it
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|