PDA

View Full Version : Solved: Selecting cells



alu
11-07-2011, 03:28 AM
I have a large spreadsheed like the one attached.

I wish to fill the ID & Name to occupy the blank rows to the next name.

I can do this at the moment using key combinations. Starting in cell A2 I use:

Ctrl+Shift+Right Arrow
Ctrl+Shift+Down Arrow
Shift+Up Arrow
Ctrl+D
Ctrl+Down Arrow

then loop back to begininng...

When I try and record this I end up with the following code:

Sub Macro1()
'
' Macro1 Macro
'
'
Range("A2").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Range("A2:B9").Select
Selection.FillDown
Selection.End(xlDown).Select
End Sub


But when I run it to fill the names for the entire spreadsheet it keeps going back to the first example I used and no further.

How can I ammend this code so it fills the name and ID down until the change in name and ID then repeats process again and again?

I think it's something to do with the code below, but i'm not too sure.

Range(ActiveCell, ActiveCell.End(xlToRight)).Copy

Thanks in advance

mdmackillop
11-07-2011, 06:14 AM
Option Explicit
Sub Filling()
Dim Rng As Range, R As Range, Cel As Range
Set Rng = Range("A:A").SpecialCells(xlCellTypeConstants)
For Each Cel In Rng
If IsNumeric(Cel) Then
If Cel.End(xlDown).Row <> Rows.Count Then
Set R = Range(Cel, Cel.End(xlDown).Offset(-1))
R.Resize(, 2).FillDown
End If
End If
Next
End Sub