If cell in column is not empty, copy value

Yulyo

Board Regular
Joined
Jul 17, 2017
Messages
94
Hi everyone,

I have the following problem:
- I have a table with 9 columns (A1:I);
- I need a VBA to look into column I and if for example I2 is not empty, to copy the value from B2 to D2, and to do this for every cell in column I. If I2 is empty, to do nothing.
I know is very easy with formula, but since this a part of a larger macro, I do not know how to make it work.

Thank you in advance.
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
maybe something like

VBA Code:
Dim cel As Range, myRng As Range
Set myRng = Range(Cells(1, "I"), Cells(Cells(Rows.count, "I").End(xlUp).row, "I"))
For Each cel In myRng
 
   If cel <> "" Then
      Cells(cel.row, 4) = Cells(cel.row, 2)
   Else
   End If
Next cel
 
Upvote 0
Another option
VBA Code:
Sub Yulyo()
   With Range("I2", Range("I" & Rows.Count).End(xlUp))
      .Offset(, -5).Value = Evaluate("if(" & .Address & "<>""""," & .Offset(, -7).Address & "," & .Offset(, -5).Address & ")")
   End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,497
Messages
6,125,155
Members
449,208
Latest member
emmac

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