Copy cells that contain text to another cell

jmkerzic

New Member
Joined
Jul 5, 2019
Messages
31

I need a formula that will copy text in column f or g (the last cell that contains text) and paste it in column e. If f or g have no text than do not paste anything in column e

Example column f (Cornish) I need copied to column e (c). Column g (freedman) to column e (And).

Column e Column F Column G
DECKER
CCORNISH
SACHAR
SHARIPOVA
DHALIWAL
JAHANT
MCLAUGHLIN
GOODMAN
MCGILL
YEARWOOD
JORTIZ
ANDJOELFREEDMAN
SMITH
BAKARE
LOZANO
FELDTMAN
ROSEAU
WALSH
MEYER
GITA
KORBAL
UGWU
EGAN
VANHALSEMA

<colgroup><col><col><col></colgroup><tbody>
</tbody>
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Try this on a copy of your data. Assumes that
- column E can be used to find the last row used
- data starts in row 2

Code:
Sub PasteValuesToE()
    Dim r As Long, E As Range, F As Range, G As Range
        With ActiveSheet
            For r = 2 To .Cells(Rows.Count, "E").End(xlUp).Row
                Set E = .Cells(r, "E")
                Set F = .Cells(r, "F")
                Set G = .Cells(r, "G")
                    If Len(G) > 0 Then
                        G.Copy E
                        G.Clear
                    ElseIf Len(F) > 0 Then
                        F.Copy E
                        F.Clear
                    End If
            Next r
        End With
End Sub
 
Last edited:
Upvote 0
I need to go to coumn I in the fomula:

I added it this to it but it only going to column G:


Sub PasteValuesToE()
Dim r As Long, E As Range, F As Range, G As Range, H As Range, I As Range
With ActiveSheet
For r = 2 To .Cells(Rows.Count, "E").End(xlUp).Row
Set E = .Cells(r, "E")
Set F = .Cells(r, "F")
Set G = .Cells(r, "G")
Set H = .Cells(r, "H")
Set I = .Cells(r, "I")
If Len(G) > 0 Then
G.Copy E
G.Clear
ElseIf Len(F) > 0 Then
F.Copy E
F.Clear
ElseIf Len(G) > 0 Then
G.Copy E
G.Clear
ElseIf Len(H) > 0 Then
H.Copy E
H.Clear
ElseIf Len(I) > 0 Then
I.Copy E
I.Clear
End If
Next r
End With
End Sub
 
Upvote 0
If you figured it out, you could post it for others reading the thread to benefit :)
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,614
Messages
6,120,517
Members
448,968
Latest member
Ajax40

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