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

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
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,216,207
Messages
6,129,508
Members
449,512
Latest member
Wabd

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