Hi, we've got a really handy piece of code (thank you to Kevin who posted it), which fills cells with the contents of the next non-blank cell above.
The code is:
We'd like if possible to change it so that the code will work on a selection of cells. So that we can then select those cells using scrolling and the mouse.
Original version before the above code is executed:
After the Kevin's code (above) is executed:
Thanks for taking a look!
The code is:
SQL:
Sub FasterFill_V4()
Dim ws As Worksheet, a, i As Long, s As String
Set ws = Worksheets("Sheet1") '<-- *** Change to actual sheet name ***
a = ws.Range("B2:B" & ws.Cells(Rows.Count, "A").End(xlUp).Row)
ReDim b(1 To UBound(a, 1), 1 To 1)
For i = 1 To UBound(a, 1)
If a(i, 1) <> "" Then s = a(i, 1)
b(i, 1) = s
Next i
ws.Range("B2").Resize(UBound(b, 1), 1).Value = b
End Sub
We'd like if possible to change it so that the code will work on a selection of cells. So that we can then select those cells using scrolling and the mouse.
Original version before the above code is executed:
change-code-to-work-on-selection-of-cells-question.xlsm | ||||
---|---|---|---|---|
A | B | |||
1 | ROW | V1 | ||
2 | 2 | alpha | ||
3 | 3 | |||
4 | 4 | |||
5 | 5 | |||
6 | 6 | 1 | ||
7 | 7 | |||
8 | 8 | |||
9 | 9 | |||
10 | 10 | 2 | ||
11 | 11 | |||
12 | 12 | |||
13 | 13 | |||
14 | 14 | charlie | ||
15 | 15 | |||
16 | 16 | |||
17 | 17 | delta | ||
18 | 18 | |||
19 | 19 | |||
20 | 20 | |||
21 | 21 | |||
22 | 22 | |||
23 | 23 | |||
24 | 24 | |||
25 | 25 | |||
Sheet1 |
After the Kevin's code (above) is executed:
change-code-to-work-on-selection-of-cells-question.xlsm | ||||
---|---|---|---|---|
A | B | |||
1 | ROW | V1 | ||
2 | 2 | alpha | ||
3 | 3 | alpha | ||
4 | 4 | alpha | ||
5 | 5 | alpha | ||
6 | 6 | 1 | ||
7 | 7 | 1 | ||
8 | 8 | 1 | ||
9 | 9 | 1 | ||
10 | 10 | 2 | ||
11 | 11 | 2 | ||
12 | 12 | 2 | ||
13 | 13 | 2 | ||
14 | 14 | charlie | ||
15 | 15 | charlie | ||
16 | 16 | charlie | ||
17 | 17 | delta | ||
18 | 18 | delta | ||
19 | 19 | delta | ||
20 | 20 | delta | ||
21 | 21 | delta | ||
22 | 22 | delta | ||
23 | 23 | delta | ||
24 | 24 | delta | ||
25 | 25 | delta | ||
Sheet1 |
Thanks for taking a look!