Moving text

handysmurf

Board Regular
Joined
Jan 17, 2015
Messages
120
Office Version
  1. 365
Platform
  1. Windows
I need to move text from one cell to another ... without overwriting the data already in the cell. Also entering a line return between the new text and old. I have many many cells that I need to do this with.

1738938488388.png


So in this example copy from C2 to D2... it would end up looking like D1
 
Try this:

VBA Code:
Sub MovingText()
  Dim i As Long, a As Variant
  
  With Range("C1:D" & Range("A" & Rows.Count).End(3))
    a = .Value
    For i = 1 To UBound(a, 1)
      If a(i, 1) <> "" Then
        a(i, 2) = a(i, 1) & Chr(10) & a(i, 2)
        a(i, 1) = ""
      End If
    Next
    .Value = a
  End With
End Sub
 
Upvote 0
Run the macro again, when the error appears, press the "Debug" button, a row is highlighted in the macro, copy the screen and paste it here.

Other doubts:
Do you have formulas in the cells?
Does any formula have an error?
Did you modify the macro at all?
 
Upvote 0
Run the macro again, when the error appears, press the "Debug" button, a row is highlighted in the macro, copy the screen and paste it here.

Other doubts:
Do you have formulas in the cells?
Does any formula have an error?
Did you modify the macro at all?
1738971969334.png


No formulas in this workbook and I didn't modify it
 
Upvote 0
Do you have data in the active sheet?

According to your image, you have data starting in cell A1.
 
Upvote 0
Suggest this change
Rich (BB code):
Sub MovingText()
  Dim i As Long, a As Variant
  
  With Range("C1:D" & Range("A" & Rows.Count).End(3).Row)
    a = .Value
    For i = 1 To UBound(a, 1)
      If a(i, 1) <> "" Then
        a(i, 2) = a(i, 1) & Chr(10) & a(i, 2)
        a(i, 1) = ""
      End If
    Next
    .Value = a
  End With
End Sub
 
Upvote 0
Solution
Suggest this change
Rich (BB code):
Sub MovingText()
  Dim i As Long, a As Variant
 
  With Range("C1:D" & Range("A" & Rows.Count).End(3).Row)
    a = .Value
    For i = 1 To UBound(a, 1)
      If a(i, 1) <> "" Then
        a(i, 2) = a(i, 1) & Chr(10) & a(i, 2)
        a(i, 1) = ""
      End If
    Next
    .Value = a
  End With
End Sub

That worked perfectly ... thank you!!
 
Upvote 0

Forum statistics

Threads
1,226,795
Messages
6,193,047
Members
453,772
Latest member
aastupin

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