Copy subtotal cell to rows below

Philip041

Board Regular
Joined
Jul 17, 2011
Messages
63
Hi,

I have some data which looks like below:

NameCountryCode
GermanyGermanyDE
JohnGermany
NancyGermany
FredGermany
BrianGermany
France
DannyFranceFR
JohnFrance
NancyFrance
FredFrance
DerrickFrance

<tbody>
</tbody>

I want to try and find a way of copying the code to the cells below it. My logic is:

Scroll down Column C (Code)
Copy first non-empty cell
Paste to next empty cell
Repeat
When get to non-empty cell copy that cell and carry out above process

Is there a way to fix this?

The data is about 30,000 rows long and my problem field is in Column H.

Any help much appreciated!
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Try something like this, I've used column A to set the last row but obviously change that to whatever column your name data is in. In the sample you posted what you asked for will post DE against France in the name column. So if your data is as above you might need to take that into account

Code:
Sub fillCells()
On Error GoTo xit:
Application.ScreenUpdating = False
Application.Calculation = xlCalculateManual
Dim FinalRow As Integer
  
  FinalRow = Cells(Rows.Count, "A").End(xlUp).Row




    For i = 2 To FinalRow
     
    If Range("H" & i).Value = "" Then Range("H" & i).Value = Range("H" & i - 1).Value




    Next i
  


xit:
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic


End Sub
 
Upvote 0
Alternatively if you use this
Code:
    If Range("H" & i).Value = "" And Range("H" & i + 1) = "" Then
        Range("H" & i).Value = Range("H" & i - 1).Value
    End If
the row where you have France in col A will not get filled in
 
Upvote 0
Paste in cell D2 assuming data is in Cell A1:C30000 INCLUDING HEADERS & COPY DOWN

=IF(C2="",D1,C2)
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,540
Messages
6,120,106
Members
448,945
Latest member
Vmanchoppy

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