Macro code to replace data

constantinet

New Member
Joined
Mar 9, 2017
Messages
16
If Column C has a certain name I would like that name to be copied over to Column A. I am unable to just do a copy and pasta as I do not need every name copied over to Column A. So for example if Column A has the following number 12345 and Column C has the name Jane Doe than I would like to replace the number in Column A with the name from Column C.
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Let's start with the following:

Code:
Sub replace_data()
    Set f = Range("C:C").Find("Jane Doe", LookIn:=xlValues, lookat:=xlWhole)
    If Not f Is Nothing Then
        Range("A" & f.Row).Value = f.Value
    End If
End Sub
 
Upvote 0
Thank you for your help. I forget one important piece of information sometimes the name Jane Doe repeats itself in Column C and when this happens I need the name moved multiple times to Column A. The above macro currently recognizes the name once, is there away to recognize the name multiple times.

Thank you again and sorry for leaving out that piece of information.
 
Upvote 0
Thank you for your help. I forget one important piece of information sometimes the name Jane Doe repeats itself in Column C and when this happens I need the name moved multiple times to Column A. The above macro currently recognizes the name once, is there away to recognize the name multiple times.

Thank you again and sorry for leaving out that piece of information.

Ok, then let's get on with this.

Code:
Sub replace_data()
    Dim r As Range, f As Range, cell As String
    Set r = Range("C:C")
    Set f = r.Find("Jane Doe", LookIn:=xlValues, lookat:=xlWhole)
    If Not f Is Nothing Then
        cell = f.Address
        Do
            Range("A" & f.Row).Value = f.Value
            Set f = r.FindNext(f)
        Loop While Not f Is Nothing And f.Address <> cell
    End If
End Sub
 
Upvote 0
Here is another macro that you can consider...
Code:
[table="width: 500"]
[tr]
	[td]Sub JaneDoe()
  Dim LastRow As Long
  LastRow = Cells(Rows.Count, "A").End(xlUp).Row
  Range("A1:A" & LastRow) = Evaluate(Replace("IF(C1:C#=""Jane Doe"",C1:C#,IF(A1:A#="""","""",A1:A#))", "#", LastRow))
End Sub[/td]
[/tr]
[/table]
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,403
Messages
6,124,710
Members
449,182
Latest member
mrlanc20

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