Macro to update filtered data in a column

tbrynard01

Board Regular
Joined
Sep 20, 2017
Messages
129
Office Version
  1. 365
Platform
  1. Windows
I have a column with variable number of rows that contains the first and last name of our counselors but I would like to filter each name and update to first name only.

Let's say Column A - as I said the number of rows will vary every day
Peter Pan
Joe Jobs
Peter Pan
Mary Lamb

Manually I can filter and select Peter Pan, update to Peter and copy down the entire range, but would like to be able to do that automatically

I hope that I've explained this clearly and would appreciate any help.

Thanks.
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Here is a VBA solution for you.

VBA Code:
Option Explicit

Sub Names()
    Dim lr As Long, i As Long
    lr = Range("A" & Rows.Count).End(xlUp).Row
    For i = 1 To lr
        Range("A" & i) = Left(Range("A" & i), WorksheetFunction.Find(" ", Range("A" & i)))
    Next i
End Sub
 
Upvote 0
How about
VBA Code:
Sub tbrynard()
   With Range("A2", Range("A" & Rows.Count).End(xlUp))
      .Value = Evaluate(Replace("if(@="""","""",left(@,find("" "",@)-1))", "@", .Address))
   End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,925
Messages
6,122,298
Members
449,077
Latest member
Rkmenon

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