Macro to copy cell value down until next non-blank cell

nodroj81

Board Regular
Joined
Mar 21, 2008
Messages
126
Hi all,

Let me lay out my problem so you can understand what I'm trying to accomplish.

In a given sheet (Sheet1), I have two columns,

A1 and B1 are column headings

column A has names, so let's say A2 = John, A17 = Fred, A47 = Larry, and A91 = Zeus. All cells between the cells mentioned are blank.

Column B has order numbers, and every cell from B2 - B125 has an order number in it.

So my array in question is A1:B125.

What I am trying to do is find a macro that will look in column A and if the cell is blank, copy the name from above. If the cell isn't blank then the cell remains unchanged. This is done until the last row of data is reached. Please note that in the example above the last row of data for column A would be A125 (not A91).

I can actually put together a working macro that would essentially insert a temp column, insert a formula, copy the values of that temp column and then delete the temp column. That just seems like an incredibly inefficient way of doing it.

Any ideas?
 
Hello all,

I got to troubleshoot something in Vidar's suggestion:
I am confused by the "c" which I assume is referring to "Cells" for now my VBA alert me for "Variable not defined error". Any suggestions? Thanks!
Trying to define the variable is not making it too.

Sub FillRow()
Dim Name As String
For Each c In Range("B2:B" & Cells(Rows.Count, 2).End(xlUp).Row)
If Cells(c.Row, 1) > "" Then
Name = Cells(c.Row, 1).Value
Cells(c.Row, 1).Copy
Else
Cells(c.Row, 1).Value = Name
Cells(c.Row, 1).PasteSpecial (xlPasteFormats)
End If
Next
End Sub
 
Upvote 0

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.

Forum statistics

Threads
1,215,084
Messages
6,123,028
Members
449,092
Latest member
ikke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top