Can i do this in excel

I have a spreadsheet that has an account number in column a.   I want that cell to replicate itself in all empty cells beneath it until it gets to the next account number.   Can I do this


what I have now
001        water      15
               fire          10
002        water      22
               garbage  20
               fire          10
              cake          15
003        cake        10
               fire           10
004

what I want
001        water      15
001       fire          10
002        water      22
002       garbage  20
002        fire          10
002       cake          15
003       cake        10
003       fire           10
004
jamesmetcalf74Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Martin LissOlder than dirtCommented:
This assumes that data starts in row 1. If not then change the FIRST_ROW constant.
Sub ReplicateAccounts()
Dim lngRow As Long
Const FIRST_ROW = 1
Dim strAccount As String

For lngRow = FIRST_ROW To ActiveSheet.UsedRange.Rows.Count
    If Cells(lngRow, "A") <> "" Then
        strAccount = Cells(lngRow, "A")
    Else
        Cells(lngRow, "A") = strAccount
    End If
Next
End Sub

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ProfessorJimJamMicrosoft Excel ExpertCommented:
yes possible.

you create a helper column.  put that formula =IF(A2="",B1,A2) B2 and copy down and then once you reach to the end copy all cells in B column and paste as value then delete the column A.

see attached.
Book1.xlsx
Martin LissOlder than dirtCommented:
My macro also assumes that the accounts are in column "A". If not then change the 3 "A"s to the proper column.

And just in case you need them, here are instructions on how to install and use the macro.

In Excel, Press Alt+F11 to open the Visual Basic Editor (VBE)

Right-click on your workbook name in the "Project-VBAProject" pane (at the top left corner of the editor window). If you don’t see an existing module then select Insert -> Module from the context menu. Otherwise just select the module.

Copy the macro (you can use the ‘Select All’ button if you like) and paste it into the right-hand pane of the VBA editor ("Module1" window)

Press Alt+F11 again to go back to Excel

Optionally, press Alt+F8 to open the "Macro" dialog window. Select the macro, click ‘Options…’,  hold down the Shift key and type the letter A (or any other letter) and click ‘OK’. Then anytime you want to run the macro press Ctrl+Shift+A.

When you close the workbook you will need to save it as an xlsm or xls file if it’s not already one of those.
Starting with Angular 5

Learn the essential features and functions of the popular JavaScript framework for building mobile, desktop and web applications.

jamesmetcalf74Author Commented:
I used Martin's.  Didn't try the other because Martin's worked.
Thanks to both of you.
Martin LissOlder than dirtCommented:
You're welcome and I'm glad I was able to help.

In my profile you'll find links to some articles I've written that may interest you.
Marty - MVP 2009 to 2015, Experts-Exchange Top Expert Visual Basic Classic 2012 to 2014
Rob HensonFinance AnalystCommented:
Don't necessarily need a helper column.

Apply an AutoFilter to the column and use the filter to display blanks.

In the first blank put a formula referring to the cell above, ie if first blank is A2, formula  =A1

Select the remainder of the column and Ctrl D to fill down. This will only populate the visible rows.

Take off the Filter and then Copy & Paste Values for the whole column if so required.

Thanks
Rob H
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.