tolio
12-23-2007, 03:19 AM
Hi people,
Just starting in VBA :bug:
I have a sheet with a dynamic range.
The first column has some empty cells that i want to fill based on the value of the upper cell.
For example i have:
A1:textA
A2:empty cell
A3:empty cell
A4: textB
A3:empty cell
A3:textC
And i want to have:
A1:textA
A2:textA
A3:textA
A4:textB
A3:textB
A3:textB
I have the following code, but it seems to fail; i select the range and run the macro but it doesn't update all the cells. Another problem is that i have to pre-select the cells, is there a way to turn this more automatic defining a dynamic range?
Sub Fillrow()
Rng = Selection.Rows.Count
ActiveCell.Offset(0, 0).Select
Application.ScreenUpdating = False
For i = 1 To Rng
If ActiveCell.Value = "" Then
ActiveCell.Offset(-1, 0).Copy
ActiveSheet.Paste
Else
ActiveCell.Offset(1, 0).Select
End If
Next i
Application.ScreenUpdating = True
End Sub
Best regards,
tolio
Just starting in VBA :bug:
I have a sheet with a dynamic range.
The first column has some empty cells that i want to fill based on the value of the upper cell.
For example i have:
A1:textA
A2:empty cell
A3:empty cell
A4: textB
A3:empty cell
A3:textC
And i want to have:
A1:textA
A2:textA
A3:textA
A4:textB
A3:textB
A3:textB
I have the following code, but it seems to fail; i select the range and run the macro but it doesn't update all the cells. Another problem is that i have to pre-select the cells, is there a way to turn this more automatic defining a dynamic range?
Sub Fillrow()
Rng = Selection.Rows.Count
ActiveCell.Offset(0, 0).Select
Application.ScreenUpdating = False
For i = 1 To Rng
If ActiveCell.Value = "" Then
ActiveCell.Offset(-1, 0).Copy
ActiveSheet.Paste
Else
ActiveCell.Offset(1, 0).Select
End If
Next i
Application.ScreenUpdating = True
End Sub
Best regards,
tolio