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!
 

MrTeeny

Board Regular
Joined
Jul 26, 2017
Messages
231
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
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
32,078
Office Version
365
Platform
Windows
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
 

SyedUsman

Board Regular
Joined
Jun 28, 2017
Messages
117
Paste in cell D2 assuming data is in Cell A1:C30000 INCLUDING HEADERS & COPY DOWN

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

Forum statistics

Threads
1,081,726
Messages
5,360,906
Members
400,602
Latest member
newaqua

Some videos you may like

This Week's Hot Topics

  • VBA (Userform)
    Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
  • List box that changes fill color
    Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
  • Remove duplicates and retain one. Cross-linked cases
    Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
  • VBA Copy and Paste With Duplicates
    Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
  • Macro
    is it possible for a macro to run if the active cell value is different to the value above it
  • IF DATE and TIME
    I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...
Top