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

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Try this:

Code:
Sub MySub()
'Modified 6/13/18 10:10 PM EDT
Application.ScreenUpdating = False
Dim i As Long
Dim c As Range
Dim Lastrow As Long
For i = 5 To 14
Lastrow = Cells(Rows.Count, i).End(xlUp).Row
    For Each c In Range(Cells(3, i), Cells(Lastrow, i))
        If c <> "" Then
            c.Offset(, 1).Value = Cells(2, i).Value
        End If
    Next
Next
Application.ScreenUpdating = True
End Sub
 
Upvote 0
If you still need more help on this you will have to explain what is did wrong.
Saying it did not work does not help me.
But maybe someone else here at Mr. Excel will be able to help.
 
Upvote 0
Here is a Sample of what I am trying to accomplish

Before


[TABLE="class: grid, width: 500, align: center"]
<tbody>[TR]
[TD]ID[/TD]
[TD]S Value[/TD]
[TD]Code[/TD]
[TD]Import Value[/TD]
[TD]Export Value[/TD]
[TD]Seq[/TD]
[TD]Exit[/TD]
[TD]Offer[/TD]
[TD]Exit Out[/TD]
[TD]FC[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]1[/TD]
[TD]A[/TD]
[TD]44[/TD]
[TD]E111[/TD]
[TD]3[/TD]
[TD]88[/TD]
[TD]L[/TD]
[TD]E99[/TD]
[TD]S101[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]


After

[TABLE="class: grid, width: 500, align: center"]
<tbody>[TR]
[/TR]
[TR]
[TD]D[/TD]
[TD]S Value[/TD]
[TD]Code[/TD]
[TD]Import Value[/TD]
[TD]Export Value[/TD]
[TD]Seq[/TD]
[TD]Exit[/TD]
[TD]Offer[/TD]
[TD]Exit Out[/TD]
[TD]FC[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]1[/TD]
[TD]A[/TD]
[TD]44[/TD]
[TD]E111[/TD]
[TD]3[/TD]
[TD]88[/TD]
[TD]L[/TD]
[TD]E99[/TD]
[TD]S101[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]1[/TD]
[TD]A[/TD]
[TD]44[/TD]
[TD]E111[/TD]
[TD]3[/TD]
[TD]88[/TD]
[TD]L[/TD]
[TD]E99[/TD]
[TD]S101[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]1[/TD]
[TD]A[/TD]
[TD]44[/TD]
[TD]E111[/TD]
[TD]3[/TD]
[TD]88[/TD]
[TD]L[/TD]
[TD]E99[/TD]
[TD]S101[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]1[/TD]
[TD]A[/TD]
[TD]44[/TD]
[TD]E111[/TD]
[TD]3[/TD]
[TD]88[/TD]
[TD]L[/TD]
[TD]E99[/TD]
[TD]S101[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]1[/TD]
[TD]A[/TD]
[TD]44[/TD]
[TD]E111[/TD]
[TD]3[/TD]
[TD]88[/TD]
[TD]L[/TD]
[TD]E99[/TD]
[TD]S101[/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD]1[/TD]
[TD]A[/TD]
[TD]44[/TD]
[TD]E111[/TD]
[TD]3[/TD]
[TD]88[/TD]
[TD]L[/TD]
[TD]E99[/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0
Try this in a copy of your workbook
Code:
Sub Fill_Values()
  With Range("F3:N" & Range("E" & Rows.Count).End(xlUp).Row)
    .SpecialCells(xlBlanks).FormulaR1C1 = "=R[-1]C"
    .Value = .Value
  End With
End Sub
 
Upvote 0
Have been out of town. Thank You for the code. Works Perfect.

Is the code copying each blank cell in the row above it, hence "=R[-1]C"
 
Upvote 0
Except for your Header row and Row 2, the cells in Columns F:N are all blank, correct? If so, then this should work...
Code:
[table="width: 500"]
[tr]
	[td]Sub FillTableFromRow2()
  Range("F3:N" & Cells(Rows.Count, "E").End(xlUp).Row).Value = Range("F2:N2").Value
End Sub[/td]
[/tr]
[/table]
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,967
Members
452,371
Latest member
Frana

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