ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Invalid use of Null error (https://www.excelbanter.com/excel-programming/313946-invalid-use-null-error.html)

Stuart[_5_]

Invalid use of Null error
 
I'm using the following code to Clean and Trim data in Col B.
Most cells in the range contain data. Most data is text.
Cell ("B1") appears to be empty.

Immediately I run the following code, I receive an "Invalid use
of Null" error in "B1" :

Sub InitialFormat()

Dim C As Range, FormatRng As Range

Set FormatRng = ActiveSheet.UsedRange.Columns(2)
For Each C In FormatRng
With C
.RowHeight = 12.75
If Not IsEmpty(C) Then
.Value = (WorksheetFunction.Clean _
(WorksheetFunction.Trim(.Text)))
End If
.Rows.AutoFit
End With
Next
End Sub

Why is this please?

Regards.



---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.778 / Virus Database: 525 - Release Date: 15/10/2004



Norman Jones

Invalid use of Null error
 
Hi Stuart,

Try changing:

Set FormatRng = ActiveSheet.UsedRange.Columns(2)


to:

Set FormatRng = ActiveSheet.UsedRange.Columns(2).Cells

As your code stands, C refers to a column rather than cell and C.Value
references an array of values.

---
Regards,
Norman



"Stuart" wrote in message
...
I'm using the following code to Clean and Trim data in Col B.
Most cells in the range contain data. Most data is text.
Cell ("B1") appears to be empty.

Immediately I run the following code, I receive an "Invalid use
of Null" error in "B1" :

Sub InitialFormat()

Dim C As Range, FormatRng As Range

Set FormatRng = ActiveSheet.UsedRange.Columns(2)
For Each C In FormatRng
With C
.RowHeight = 12.75
If Not IsEmpty(C) Then
.Value = (WorksheetFunction.Clean _
(WorksheetFunction.Trim(.Text)))
End If
.Rows.AutoFit
End With
Next
End Sub

Why is this please?

Regards.



---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.778 / Virus Database: 525 - Release Date: 15/10/2004





Stuart[_5_]

Invalid use of Null error
 
Regards and thanks.

"Norman Jones" wrote in message
...
Hi Stuart,

Try changing:

Set FormatRng = ActiveSheet.UsedRange.Columns(2)


to:

Set FormatRng = ActiveSheet.UsedRange.Columns(2).Cells

As your code stands, C refers to a column rather than cell and C.Value
references an array of values.

---
Regards,
Norman



"Stuart" wrote in message
...
I'm using the following code to Clean and Trim data in Col B.
Most cells in the range contain data. Most data is text.
Cell ("B1") appears to be empty.

Immediately I run the following code, I receive an "Invalid use
of Null" error in "B1" :

Sub InitialFormat()

Dim C As Range, FormatRng As Range

Set FormatRng = ActiveSheet.UsedRange.Columns(2)
For Each C In FormatRng
With C
.RowHeight = 12.75
If Not IsEmpty(C) Then
.Value = (WorksheetFunction.Clean _
(WorksheetFunction.Trim(.Text)))
End If
.Rows.AutoFit
End With
Next
End Sub

Why is this please?

Regards.



---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.778 / Virus Database: 525 - Release Date: 15/10/2004






---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.778 / Virus Database: 525 - Release Date: 15/10/2004




All times are GMT +1. The time now is 05:43 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com