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

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
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


IDS ValueCodeImport ValueExport ValueSeqExitOfferExit OutFC
11A44E111388LE99S101
2
3
4
5
6

<tbody>
</tbody>


After

DS ValueCodeImport ValueExport ValueSeqExitOfferExit OutFC
11A44E111388LE99S101
21A44E111388LE99S101
31A44E111388LE99S101
41A44E111388LE99S101
51A44E111388LE99S101
61A44E111388LE99

<tbody>
</tbody>
 
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,215,267
Messages
6,123,964
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