Panoos64

Well-known Member
Joined
Mar 1, 2014
Messages
882
Hi all, i would like to write a VBA code so that to run through col. "E" and where find number should place it in col. "D" either the cell is blank or not. Below i present the original data and the expected result.

Many thanks in advance



A BCDE
101/05/20161010102457.25125.36
201/05/20161010105200.36
302/05/20161010108101.35253.65
403/05/2016
1010123220.23
504/05/20162015456478.36

<colgroup><col style="mso-width-source:userset;mso-width-alt:1133;width:23pt" width="31"> <col style="width:48pt" width="64" span="5"> </colgroup><tbody>
</tbody>





A BCDE
1
01/05/2016
1010102125.36
201/05/2016
1010105200.36
302/05/20161010108
253.65
403/05/2016
1010123
220.23
504/05/20162015456478.36

<colgroup><col style="mso-width-source:userset;mso-width-alt:1133;width:23pt" width="31"> <col style="width:48pt" width="64" span="5"> </colgroup><tbody>
</tbody>
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Here is a way that uses no loops.
Code:
Sub MyReplace()

    Dim lRow As Long
    
    Application.ScreenUpdating = False
    
'   Find last row with data in column A
    lRow = Cells(Rows.Count, "A").End(xlUp).Row
    
'   Enter temporary formulas in column F
    Range("F1:F" & lRow).FormulaR1C1 = "=IF(RC[-1]<>"""",RC[-1],RC[-2])"
    
'   Copy values from column F to column D
    Range("F1:F" & lRow).Copy
    Range("D1").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    
'   Clear columns E and F
    Columns("E:F").ClearContents
    
    Application.ScreenUpdating = True
    
End Sub
 
Upvote 0
How about
Code:
Sub MoveColE()
   With Range("D2", Range("D" & Rows.Count).End(xlUp))
      .Value = Evaluate(Replace(Replace("if(@e<>"""",@e,@)", "@e", .Offset(, 1).Address), "@", .Address))
   End With
   Columns(5).ClearContents
End Sub
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0
Here is one more for you to consider (similar in concept to what Fluff posted, but using a different set of function calls)...
Code:
[table="width: 500"]
[tr]
	[td]Sub CopyEtoD()
  Dim LastRow As Long
  LastRow = Cells(Rows.Count, "A").End(xlUp).Row
  Range("D2:D" & LastRow) = Evaluate(Replace("IF(E2:E#="""",D2:D#,E2:E#)", "#", LastRow))
  Range("E2:E" & LastRow).ClearContents
End Sub[/td]
[/tr]
[/table]
 
Last edited:
Upvote 0
Thank you Rick, the code works right and base to my data, Thanks once again for your support. Hv a lovely day
 
Upvote 0

Forum statistics

Threads
1,214,585
Messages
6,120,394
Members
448,957
Latest member
Hat4Life

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