populate cells based on condition

dave92

New Member
Joined
Jun 20, 2018
Messages
3
So this might have already been answered.
I'm trying to populate the blank rows in column B with the value in the previous row. But when the field is already populated (ie 123), don't do anything. In the next blank cell, use 123 value to populate. below is an example. Thanks in advance!

Col A Col B Col C
Feature ABC description of feature
Story <blank> description of story
Story <blank> description of story
Feature 123 description of feature
Story <blank> description of story
Story <blank> description of story

Into this
Col A Col B Col C
Feature ABC description of feature
Story ABC description of story
Story ABC description of story
Feature 123 description of feature
Story 123 description of story
Story 123 description of story</blank></blank></blank></blank>
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
From looking at your example I'm having trouble knowing what is in column A and what is in column B and column C

So are you saying if George is in Row(1) column B
And Row(2) column B is empty Then Row(2) Column B should now have George
 
Upvote 0
From looking at your example I'm having trouble knowing what is in column A and what is in column B and column C

So are you saying if George is in Row(1) column B
And Row(2) column B is empty Then Row(2) Column B should now have George


correct. row 2 col B is empty and it needs to be populated with what is in row 1 col B which is George.
 
Upvote 0
Try this:
Code:
Sub Test()
'Modified 6/20/2018 2:59 PM  EDT
Application.ScreenUpdating = False
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "A").End(xlUp).Row
    For i = 2 To Lastrow
        If Cells(i, 2).Value = "" Then Cells(i, 2).Value = Cells(i, 2).Offset(-1).Value
    Next
Application.ScreenUpdating = True
End Sub
 
Last edited:
Upvote 0
Another option
Code:
Sub filldownBlank()
   With Range("B:B")
      .SpecialCells(xlBlanks).FormulaR1C1 = "=r[-1]c"
      .Value = .Value
   End With
End Sub
 
Upvote 0
Try this:
Code:
Sub Test()
'Modified 6/20/2018 2:59 PM  EDT
Application.ScreenUpdating = False
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "A").End(xlUp).Row
    For i = 2 To Lastrow
        If Cells(i, 2).Value = "" Then Cells(i, 2).Value = Cells(i, 2).Offset(-1).Value
    Next
Application.ScreenUpdating = True
End Sub

this works. How does the macro change if it's the column I'm trying to copy is in column C and not B? thanks again
 
Upvote 0
Try this:

See the C

Code:
Sub Test_New()
'Modified 6/20/2018 4:20 PM  EDT
Application.ScreenUpdating = False
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "A").End(xlUp).Row
    For i = 2 To Lastrow
        If Cells(i, "[COLOR=#ff0000]C[/COLOR]").Value = "" Then Cells(i, "[COLOR=#ff0000]C[/COLOR]").Value = Cells(i, "[COLOR=#ff0000]C[/COLOR]").Offset(-1).Value
    Next
Application.ScreenUpdating = True
End Sub

Script assumes there are always values in column A
It continues looking till it finds no more values in column A
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,902
Messages
6,175,278
Members
452,629
Latest member
SahilPolekar

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