Macro to update filtered data in a column

tbrynard01

Board Regular
Joined
Sep 20, 2017
Messages
92
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.
 

Some videos you may like

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.

alansidman

Well-known Member
Joined
Feb 26, 2007
Messages
6,140
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
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
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,224
Office Version
  1. 365
Platform
  1. Windows
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
 

Watch MrExcel Video

Forum statistics

Threads
1,126,901
Messages
5,621,564
Members
415,846
Latest member
Jrider1

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
Top