Copy Non-Blank Text from Column 3 to Column 2

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,595
Office Version
  1. 2021
Platform
  1. Windows
I have written VBA code to copy Non-Blank Text from cloumn 3 to column 2 which I have listed below. The code is not doing anything.

FinalRow = Cells(65536, 1).End(xlUp).Row
For I = FinalRow To 1 Step 1
If Cells(I, 3).Value <> "" Then
Cells(I, 3).Selection.Copy
Cells(I, 2).Selection.Paste
End If
Next I
End Sub


It would be appreciated if someone could assist
[/list][/list]
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Bueno, no veo donde hay la parte de su mensaje que require ayuda en un idioma que no sea inglés. Pero para que sepa, su error fue que el paso de su bucle es positivo. Si usted necesita caminar al revés ponga un paso negativo.
Code:
Sub foo()
    Dim lngFinalRow As Long, lngRow As Long
    
    lngFinalRow = Cells(65536, 1).End(xlUp).Row
    For lngRow = lngFinalRow To 1 Step -1
        With Cells(lngRow, 3)
            If .Value <> vbNullString Then .Copy .Offset(, -1)
        End With
    Next lngRow
End Sub
O camine el bucle normalmente - de abajo para arriba...
Code:
Sub foo()
    Dim lngFinalRow As Long, lngRow As Long
    
    lngFinalRow = Cells(65536, 1).End(xlUp).Row
    For lngRow = 1 to lngFinalRow 
        With Cells(lngRow, 3)
            If .Value <> vbNullString Then .Copy .Offset(, -1)
        End With
    Next lngRow
End Sub
 
Upvote 0
Thanks for all the help. MaVBA code working perfectly.
 
Upvote 0

Forum statistics

Threads
1,223,956
Messages
6,175,616
Members
452,661
Latest member
Nonhle

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