Need help fast w/ vba!

nrguerrieri

New Member
Joined
May 10, 2018
Messages
39
Office Version
  1. 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.
 
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
 
Upvote 0

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
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

Thank you so much. that worked.

Now, im trying to do that last part. So copying from above and pasting below to all the blanks below until there is a value. then where there is a value. copy that and paste to all the blanks below that, and so on. I am getting an error for some reason with my code below here.

Any clue why its not working?

Sub abc()

Dim lastRow
lastRow = Cells.Find(What:="*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
For ptr = 2 To lastRow
If Cells(ptr, "A") = vbNullString Then
Cells(ptr, "A") = Cells(ptr, "A").Offset(-1, 0)
End If
Next

End Sub
 
Last edited:
Upvote 0
If you trying to look down column A.
And if some cell in column A is empty then enter cell value above
Try this:
If this is not what you want then explain more.

Code:
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
 
Last edited:
Upvote 0
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
Here is another macro to consider... it produces the same output as the macro above, but without using an loops.
Code:
[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]
 
Upvote 0

Forum statistics

Threads
1,215,049
Messages
6,122,864
Members
449,097
Latest member
dbomb1414

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top