ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   A simple maco for someone, but not for me. (https://www.excelbanter.com/excel-programming/310647-simple-maco-someone-but-not-me.html)

Bill Wilson[_3_]

A simple maco for someone, but not for me.
 
I have a long column of numbers, but some of them are
blank. Here is what it looks like:

(Top of Column)
Blank Cell
Blank Cell
478
Blank Cell
Blank Cell
Blank Cell
Blank Cell
Blank Cell
6009

I want to fill the blank cells with the numbers from the
bottom, so it looks like this:

(Top of Column)
478
478
478
6009
6009
6009
6009
6009
6009

See my problem? I forsee a simple little macro which
starts at the bottom number in the column, copies it, and
moves up one cell. If the new cell is blank, it pastes
the number and moves up one more cell, etc. When the new
cell already has a number, it copies that number and
pastes it into the blank cells above it. How do you
write this sucker?

Thank you for your help.



Harald Staff

A simple maco for someone, but not for me.
 
Sub tester()
Dim S As String
Dim L As Long
Dim Col As Long

Col = 1 ' A column

For L = Cells(65000, Col).End(xlUp).Row To 1 Step -1
If Cells(L, Col).Formula = "" Then
Cells(L, Col).Formula = S
Else
S = Cells(L, Col).Formula
End If
Next

End Sub

HTH. Best wishes Harald

"Bill Wilson" skrev i melding
...
I have a long column of numbers, but some of them are
blank. Here is what it looks like:

(Top of Column)
Blank Cell
Blank Cell
478
Blank Cell
Blank Cell
Blank Cell
Blank Cell
Blank Cell
6009

I want to fill the blank cells with the numbers from the
bottom, so it looks like this:

(Top of Column)
478
478
478
6009
6009
6009
6009
6009
6009

See my problem? I forsee a simple little macro which
starts at the bottom number in the column, copies it, and
moves up one cell. If the new cell is blank, it pastes
the number and moves up one more cell, etc. When the new
cell already has a number, it copies that number and
pastes it into the blank cells above it. How do you
write this sucker?

Thank you for your help.





Tushar Mehta

A simple maco for someone, but not for me.
 
A non loop solution that has undergone minimal testing:
Option Explicit

Sub testIt()
Range(Range("a1"), Cells(Rows.Count, 1).End(xlUp)) _
.SpecialCells(xlCellTypeBlanks).Formula = "=a2"
End Sub

--
Regards,

Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions

In article ,
says...
I have a long column of numbers, but some of them are
blank. Here is what it looks like:

(Top of Column)
Blank Cell
Blank Cell
478
Blank Cell
Blank Cell
Blank Cell
Blank Cell
Blank Cell
6009

I want to fill the blank cells with the numbers from the
bottom, so it looks like this:

(Top of Column)
478
478
478
6009
6009
6009
6009
6009
6009

See my problem? I forsee a simple little macro which
starts at the bottom number in the column, copies it, and
moves up one cell. If the new cell is blank, it pastes
the number and moves up one more cell, etc. When the new
cell already has a number, it copies that number and
pastes it into the blank cells above it. How do you
write this sucker?

Thank you for your help.





All times are GMT +1. The time now is 10:09 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com