Copy subtotal cell to rows below

Philip041

Board Regular
Joined
Jul 17, 2011
Messages
63
Hi,

I have some data which looks like below:

[TABLE="width: 500"]
<tbody>[TR]
[TD]Name[/TD]
[TD]Country[/TD]
[TD]Code[/TD]
[/TR]
[TR]
[TD]Germany[/TD]
[TD]Germany[/TD]
[TD]DE[/TD]
[/TR]
[TR]
[TD]John[/TD]
[TD]Germany[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Nancy[/TD]
[TD]Germany[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Fred[/TD]
[TD]Germany[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Brian[/TD]
[TD]Germany[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]France[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Danny[/TD]
[TD]France[/TD]
[TD]FR[/TD]
[/TR]
[TR]
[TD]John[/TD]
[TD]France[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Nancy[/TD]
[TD]France[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Fred[/TD]
[TD]France[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Derrick[/TD]
[TD]France[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

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

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
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,224,823
Messages
6,181,180
Members
453,021
Latest member
Justyna P

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