To copy down till the next non blank cell using vba

hets

New Member
Joined
Aug 17, 2012
Messages
41
Hello everyone,

Is there any way possible to do this:
In column A, I need to find the first non blank cell, then copy that text down in the blank cells that follow UNTIL the next non blank cell. Then pick up the next text item and copy it down UNTIL etc. (but stopping at the last row of data) Is there a way to do this?

Thank you in advance
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Try this.. Adjust to your needs.

Code:
Sub abc()
 For ptr = 2 To 20
  If Cells(ptr, "A") = vbNullString Then
    Cells(ptr, "A") = Cells(ptr, "A").Offset(-1, 0)
  End If
 Next
End Sub
 
Upvote 0
Thank you for that. How can I change it to apply to the whole of column A? (Instead of just till A20)
 
Upvote 0
Without seeing or knowing the structure of your sheet try this

Code:
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

Forum statistics

Threads
1,215,266
Messages
6,123,962
Members
449,137
Latest member
yeti1016

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