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

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
We need to know what column you want to check it must be something like:

E G I L or something like this I assume.
 
Upvote 0
If column E has a value then insert the value of F2 in the entire column F & same for Column G, H etc...
 
Upvote 0
No sir.

I have a value in F2 I would like to copy that value in all rows in Column F if the adjacent column E is not blank. Then copy the value in G2 in all rows in Column G. Then copy the value in Column H in all rows in Column H.......
 
Upvote 0
But you keep doing this:

Column H.......

And this:
Column G, H etc...

Which means on an on and on.

So I never know when you want to stop.

Etc. means on and on and on and on

and H......

I would think means on and on and on.
 
Upvote 0
I think someone else here at Mr. Excel will need to help you.
Because I'm trying to write you a loop that starts at column F and go to column ???
And for some reason your not able to tell me when to stop or at least i cannot figure out from the information you have provided when to stop.

But I know there are a lot of other people here at Mr. Excel who may have a answer for you.

This is beyond my knowledgebase.
I will continue to monitor this thread to see what I can learn.
 
Upvote 0
Try this:
Code:
Sub MySub()
'Modified 6/13/18 8:45 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(2, i), Cells(Lastrow, i))
        If c <> "" Then
            c.Offset(, 1).Value = Cells(2, i).Value
        End If
    Next
Next
Application.ScreenUpdating = True
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,828
Messages
6,181,201
Members
453,022
Latest member
RobertV1609

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