Hi All.
VBA newbie here with experience in MatLab so there is vague familiarity with syntax and the logic operators (if, while, for, etc.)
So I have a column of data points with blank cells scattered about. I have used http://www.cpearson.com/Excel/NoBlanks.aspx to convert the column into an array without any empty cells. The next problem I have is inputting blank cells between differing grid points. I would like to input an empty cell wherever Left(Cell-1,1) is not equal to Left(cell,1) (basically whenever the first character in a string of a column vector is different from previous row). This is the function used:
Function NoBlanks(RR As Range) As Variant
Dim Arr() As Variant
Dim R As Range
Dim N As Long
Dim L As Long
If RR.Rows.Count > 1 And RR.Columns.Count > 1 Then
NoBlanks = CVErr(xlErrRef)
Exit Function
End If
If Application.Caller.Cells.Count > RR.Cells.Count Then
N = Application.Caller.Cells.Count
Else
N = RR.Cells.Count
End If
ReDim Arr(1 To N)
N = 0
For Each R In RR.Cells
If Len(R.Value) > 0 Then
N = N + 1
Arr(N) = R.Value
End If
Next R
For L = N + 1 To UBound(Arr)
Arr(L) = vbNullString
Next L
ReDim Preserve Arr(1 To L)
If Application.Caller.Rows.Count > 1 Then
NoBlanks = Application.Transpose(Arr)
Else
NoBlanks = Arr
End If
End Function
If anyone has any insight in how to go about achieving this I would be very thankful.
VBA newbie here with experience in MatLab so there is vague familiarity with syntax and the logic operators (if, while, for, etc.)
So I have a column of data points with blank cells scattered about. I have used http://www.cpearson.com/Excel/NoBlanks.aspx to convert the column into an array without any empty cells. The next problem I have is inputting blank cells between differing grid points. I would like to input an empty cell wherever Left(Cell-1,1) is not equal to Left(cell,1) (basically whenever the first character in a string of a column vector is different from previous row). This is the function used:
Function NoBlanks(RR As Range) As Variant
Dim Arr() As Variant
Dim R As Range
Dim N As Long
Dim L As Long
If RR.Rows.Count > 1 And RR.Columns.Count > 1 Then
NoBlanks = CVErr(xlErrRef)
Exit Function
End If
If Application.Caller.Cells.Count > RR.Cells.Count Then
N = Application.Caller.Cells.Count
Else
N = RR.Cells.Count
End If
ReDim Arr(1 To N)
N = 0
For Each R In RR.Cells
If Len(R.Value) > 0 Then
N = N + 1
Arr(N) = R.Value
End If
Next R
For L = N + 1 To UBound(Arr)
Arr(L) = vbNullString
Next L
ReDim Preserve Arr(1 To L)
If Application.Caller.Rows.Count > 1 Then
NoBlanks = Application.Transpose(Arr)
Else
NoBlanks = Arr
End If
End Function
If anyone has any insight in how to go about achieving this I would be very thankful.