Insert Value if range Not Blank

billandrew

Well-known Member
Joined
Mar 9, 2014
Messages
743
Would like to apply the value of the cell in row 2 to all rows below if the adjacent column is <> blank.

This code works, however I have to repeat for the next (possible) several columns.

Any assist would be appreciated.

Initial ex.

Code:
dim c as long, rng as long
Set rng = Range("E2", Range("E" & Rows.Count).End(xlUp))    For Each c In rng
    If c <> "" Then
    c.Offset(, 1).Value = Cells(2, 6).Value
    End If
    Next


Next ex

Code:
For Each d In rng    If d <> "" Then
    d.Offset(, 2).Value = Cells(2, 7).Value
    End If
    Next
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Thank You for the code. Works Perfect.
You're welcome.


Is the code copying each blank cell in the row above it, hence "=R[-1]C"
Yes, so if it happened that, say, row 6 had other data across it, then the blank cells below row 6 would get filled from row 6 whereas blank cells above row 6 would get filled from row 2.
 
Upvote 0

Forum statistics

Threads
1,215,268
Messages
6,123,975
Members
449,137
Latest member
yeti1016

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