Need to delete characters in a column

KAZSTREBOR

New Member
Joined
Feb 18, 2021
Messages
6
Office Version
  1. 365
Platform
  1. Windows
Hi there!

I need to delete characters generated from a report that come after the space. (eg. 1234 cds), the characters vary so I can't target specific ones.
I'm currently trying to use this code in VBA that I modified from this thread but I can't figure out why it is also deleting the first character in the cell. I'm pretty new to this so any
help is much appreciated. Thanks!

VBA Code:
Sub Test()
    Application.ScreenUpdating = False
    Dim LastRow As Long
    LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    Dim rng As Range
    On Error Resume Next
    For Each rng In Range("B1:B" & LastRow)
        rng = Left(Mid(rng, 2, 9999), WorksheetFunction.Find(" ", rng) - 2)
    Next rng
    Application.ScreenUpdating = True
End Sub
 

Some videos you may like

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,412
Office Version
  1. 365
Platform
  1. Windows
Hi & welcome to MrExcel.
How about
VBA Code:
Sub Kazstrebor()
   With Range("B1", Range("B" & Rows.Count).End(xlUp))
      .Value = Evaluate(Replace("left(@,find("" "",@&"" ""))", "@", .Address))
   End With
End Sub
 

mikerickson

MrExcel MVP
Joined
Jan 15, 2007
Messages
23,958
Perhaps TextToColumns.
VBA Code:
With Range("B:B")
    Range(.Cells(1, 1), .Cells(Rows.Count).End(xlUp)).TextToColumns Destination:=.Cells(1,1), DataType:=xlDelimited, _
        TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=True, Tab:=False, Semicolon:=False, Comma:=False, _
        Space:=True, Other:=False, FieldInfo:=Array(Array(1, 1), Array(2, 9), Array(3, 9), Array(4, 9), Array(5, 9), Array(10, 9)), TrailingMinusNumbers:=True
End With
 
Solution

Watch MrExcel Video

Forum statistics

Threads
1,127,326
Messages
5,624,018
Members
416,006
Latest member
PCaffrey

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