Macro - copy cell contents IF

G

Guest

Hope you can help, need to move a value in one cell to another only IF the
first cell is not empty.

In a function it would be:

in cell B2 - - - - > =IF(C2="","",C2)

What I have now:
Col1 Col2
AAA

BBB
CCC

What I would like to end up with:
Col1 Col2
AAA AAA

BBB BBB
CCC CCC

Thanks in advance!
 
D

dok112

You could use a loop...see below

Sub Loop()
On Error Resume Next
Dim r As Variant
Dim WSN As Variant
Set WSN = Thisworkbook.Sheets("Sheet1") 'put the sheet name here
r = 1
Do
If WSN.Cells(r, 1).Value = "" Then
r = r + 1
Else:
WSN.Cells(r, 2).Value = WSN.Cells(r, 1)
r = r + 1
End If
Loop
End Sub

This would do what you want...If you need more help, let me know...
 
G

Guest

Is there a way to do this where I can be more specific?

Say only look at column F, and copy values to column D.

Any ideas?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top