Hi, I am trying to move text up in a range when there is empty rows above or in between. I thought I had got it to work but I just found out a big problem, it clears and copies the wrong rows.
Does anyone of you experts think you could help me out with this problem?
Here is an example of the problem:
If I got:
1
empty
3
4
5
This should be:
1
3
4
5
But now the outcome is:
1
3
3
4
(as you can see, 3 is copied and 5 is deleted. The text should just move up).
The code I am using is this:
Does anyone of you experts think you could help me out with this problem?
Here is an example of the problem:
If I got:
1
empty
3
4
5
This should be:
1
3
4
5
But now the outcome is:
1
3
3
4
(as you can see, 3 is copied and 5 is deleted. The text should just move up).
The code I am using is this:
Code:
Public Sub RowRange()
Dim oRange As Range
Set oRange = Range("A36:G164")
MoveTextUp oRange
End Sub
Public Sub MoveTextUp(ByRef oRange As Range)
Dim i As Integer
Dim j As Integer
For i = 1 To oRange.Rows.Count
If oRange.Value2(i, 1) = "" Then
If Intersect(oRange, oRange(i, 1).End(xlDown)) Is Nothing Then Exit Sub
For j = 1 To 6 Step 1
oRange(i, j).Value = oRange(i, j).End(xlDown).Value
oRange(i, j).End(xlDown).Value = ""
Next
End If
Next
End Sub
Last edited: