nrguerrieri
New Member
- Joined
- May 10, 2018
- Messages
- 39
- Office Version
- 365
Need a macro that will find every cell that contains text within columns A to E all the way down to the bottom. Then paste them in that exact order, but all in column A.
Sub Search_Range()
'Modified 5/10/2018 7:30 PM EDT
Application.ScreenUpdating = False
Dim c As Range
Dim Lastrow As Long
Dim i As Long
i = 1
Dim b As Long
For b = 1 To 5
Lastrow = Cells(Rows.Count, b).End(xlUp).Row
For Each c In Cells(1, b).Resize(Lastrow)
If c.Value <> "" Then
ans = c.Row
c.Copy Cells(ans, 1)
End If
Next
Next
Application.ScreenUpdating = True
End Sub
Try this:
Code:Sub Search_Range() 'Modified 5/10/2018 7:30 PM EDT Application.ScreenUpdating = False Dim c As Range Dim Lastrow As Long Dim i As Long i = 1 Dim b As Long For b = 1 To 5 Lastrow = Cells(Rows.Count, b).End(xlUp).Row For Each c In Cells(1, b).Resize(Lastrow) If c.Value <> "" Then ans = c.Row c.Copy Cells(ans, 1) End If Next Next Application.ScreenUpdating = True End Sub
Sub abc()
'Modified 5/10/18 11:14 PM EDT
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "A").End(xlUp).Row
Dim i As Long
For i = 2 To Lastrow
If Cells(i, "A") = vbNullString Then
Cells(i, "A") = Cells(i, "A").Offset(-1, 0).Value
End If
Next
End Sub
Here is another macro to consider... it produces the same output as the macro above, but without using an loops.Try this:
Code:Sub Search_Range() 'Modified 5/10/2018 7:30 PM EDT Application.ScreenUpdating = False Dim c As Range Dim Lastrow As Long Dim i As Long i = 1 Dim b As Long For b = 1 To 5 Lastrow = Cells(Rows.Count, b).End(xlUp).Row For Each c In Cells(1, b).Resize(Lastrow) If c.Value <> "" Then ans = c.Row c.Copy Cells(ans, 1) End If Next Next Application.ScreenUpdating = True End Sub
[table="width: 500"]
[tr]
[td]Sub Search_Range()
With Range("A1:A" & Columns("B:E").Find("*", , xlValues, , xlRows, xlPrevious, , , False).Row)
.Formula = "=IFERROR(INDEX(OFFSET(B1,ROW(A$1:A$7)-1,0,1,5),MATCH(""*"",OFFSET(B1,ROW(A$1:A$7)-1,0,1,5),0)),"""")"
.Value = .Value
End With
End Sub[/td]
[/tr]
[/table]