VBA or Macro to auto fill a selected range

B

Btibert

Hello everyone,

Here is my problem. I have a spreadsheet with four columns, which are
variables nested within each other. What I am currently doing is going
through a range, finding the blank cells, filling all the blanks with
the value of the non-blank cell above it, and filling these blanks
until I reach a non-blank cell. Simply put, all I am doing is clicking
on the cell's handle and filling the blanks (it only fills the cells
down until it finds a cell with a value).

I am tediously going through each range of cells, autofilling down, and
working from right to left.

There must be an easier way where I can select the range of cells, run
a macro, and it does the autofill for me.

Any suggestions?

Thanks in advance,

Brock
 
E

Earl Kiosterud

Brock,

A macro is actually VBA. This is an unusual request, but try this:

Sub FillCells()
Dim MyRange As Range, cel As Range
Set MyRange = Range(Cells(1, 1), Cells(9, 4))
'Set MyRange = Range("A1:D9")

For Each cel In MyRange
If cel.Offset(1, 0) = "" Then cel.Copy Destination:=cel.Offset(1, 0)
Next cel
End Sub

Use the Set MyRange statement that's the most convenient. Set it to your
range, not including the bottom row.
 
B

Btibert

I truly appreciate your help. Doing a simple test, it appears as if it
does the trick.

While it may be a strange request, my file that I am working with
contains over 5000 rows of data, therefore, the process I was using
earlier was quite tedious.

Regardless, I really appreciate your assistance and thank you for
taking the time to assist.

Thanks,

Brock
 

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