copy text of cells down to blank cells

G

Guest

how can i create a macro
let's say

column n

row2 al
row3
row4
row5 ps
row6
row7 ax
row8
row9

go to column "n", select first cell with text, copy that text to blank cells
below until it gets to another cell with text, copy that text to blank cells
below, and continue the same procedure until no more cells with text

result should be

row2 al
row3 al
row4 al
row5 ps
row6 ps
row7 ax
row8 ax
row9 ax

thanks a lot
 
A

acampbell012

Modify ranges as needed:

Sub SameAsAbove()
'Copies data from cell above if current cell in range is blank
Dim MyRange As Range
Dim MyCell As Range
Dim Endrow As Integer
Endrow = Range("A65536").End(xlUp).Row
Set MyRange = Range("A1:G" & Endrow)
MyRange.Select
On Error Resume Next
For Each MyCell In MyRange
If MyCell.Value = "" Then
MyCell.Value = MyCell.Offset(-1, 0).Value
End If
Next MyCell
End Sub
 
P

PCLIVE

This code should do what you want. this assumes that row 9 is your last
row. You can modify as appropriate.

Sub test()
Range("N2").Select
txt = ActiveCell.Value

Repeat:

If Range("N" & ActiveCell.Row + 1) = "" _
Then
LastRow = Range("N" & (ActiveCell.Row)).End(xlDown).Offset(-1,
0).Row
Range("N" & (ActiveCell.Row + 1) & ":N" & LastRow).Select

If Selection.End(xlDown).Row = 65536 _
Then
Range("N" & (ActiveCell.Row) & ":N9").Select
Selection.Value = txt
End
Else:
Selection.Value = txt
txt = Range("N" & LastRow + 1).Value
End If
Range(Selection.Address).End(xlDown).Select
Else:
End If
GoTo Repeat

End Sub


Regards
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top