I'm trying to get Excel to figure out which columns of a worksheet are blank. Eventually the idea is to get it to delete the completely blank columns. Here's the code I have so far:
Sub Macro2()
'
' Macro2 Macro
'
Dim totalCols As Integer
Dim totalRows As Integer
totalCols = ActiveSheet.UsedRange.Columns.Count
totalRows = ActiveSheet.UsedRange.Rows.Count
Dim i As Integer
Dim j As Integer
Dim numNull As Integer
For i = 1 To totalCols
For j = 2 To totalRows
Dim location As String
location = "R" & i & ":" & "C" & j
If Range(location).Select = "" Then
numNull = numNull + 1
End If
Next j
If numNull = totalRows - 1 Then
MsgBox ("Column " & i & "is null")
End If
Next i
End Sub
At the end it checks to see if numNull (number of null entries in the row) = totalRows minus the header. I had it working up until the statement If Range(location).Select = "". Now the compiler says:
Method 'Range' of object '_Global' failed
Does anyone know what this means or how I can fix it?
location = "R" & i & ":C" & jalas with a colon in between ?