data.SetText Range("A1:B22").Text gives error 94 Invalid use of Null
- User
data.SetText Range("A1:B22").Text gives error 94 Invalid use of Null
- Assistant
The error message "Invalid use of Null" occurs when the code is trying to perform an operation on a variable or expression that contains a Null value. In this case, the error is likely occurring because one or more cells in the range A1:B22 contains a Null value.
To avoid this error, you can add an additional check to make sure that the cell does not contain a Null value before trying to read its text. For example, you can modify the code as follows:
codeDim rng As Range Dim cell As Range Dim text As String Set rng = Range("A1:B22") For Each cell In rng If Not IsNull(cell.Value) Then ' Check for Null value text = text & cell.Text & vbCrLf End If Next cell data.SetText textThis code loops through each cell in the range and checks whether it contains a Null value. If the cell does not contain a Null value, it appends its text to the
textvariable. Finally, theSetTextmethod is called with thetextvariable as the argument.