Delete text after enter key

Mad1ron

New Member
Joined
Jul 29, 2021
Messages
24
Office Version
  1. 365
Platform
  1. Windows
Hi all,
I have a problem about enter key :D I took data from the internet and in column f there is a lot of unnecessary information. I just need the first sentence, they hit the enter key after the first sentence. Is there any way I can do it with vba? Thanks!!
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.

TheVillageIdiot

Board Regular
Joined
Dec 9, 2011
Messages
63
CHAR(10) is a Carriage Return / Enter

With your text in A1, try the following:
=IF(ISERROR(FIND(CHAR(10),A1)),A1,LEFT(A1,FIND(CHAR(10),A1)-1))

I think that there are other Enter key equivalents, so you may have to expand the formula.
 

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
52,243
Office Version
  1. 365
Platform
  1. Windows
If it is a CHAR(10) and ...

  • you want to extract in a different column by formula, you could do it more simply with
    Excel Formula:
    =LEFT(F1,FIND(CHAR(10),F1&CHAR(10))-1)

  • you want to do it in the same column with vba, you could try this (with a copy of your data

VBA Code:
Sub JustFirst()
  With Range("F1", Range("F" & Rows.Count).End(xlUp))
    .Value = Evaluate(Replace("left(#,find(char(10),#&char(10))-1)", "#", .Address))
  End With
End Sub
 
Solution

Mad1ron

New Member
Joined
Jul 29, 2021
Messages
24
Office Version
  1. 365
Platform
  1. Windows
CHAR(10) is a Carriage Return / Enter

With your text in A1, try the following:
=IF(ISERROR(FIND(CHAR(10),A1)),A1,LEFT(A1,FIND(CHAR(10),A1)-1))

I think that there are other Enter key equivalents, so you may have to expand the formula.
Thanks for your reply but they want me do with vba :)
 

Mad1ron

New Member
Joined
Jul 29, 2021
Messages
24
Office Version
  1. 365
Platform
  1. Windows
If it is a CHAR(10) and ...

  • you want to extract in a different column by formula, you could do it more simply with
    Excel Formula:
    =LEFT(F1,FIND(CHAR(10),F1&CHAR(10))-1)

  • you want to do it in the same column with vba, you could try this (with a copy of your data

VBA Code:
Sub JustFirst()
  With Range("F1", Range("F" & Rows.Count).End(xlUp))
    .Value = Evaluate(Replace("left(#,find(char(10),#&char(10))-1)", "#", .Address))
  End With
End Sub
Thank you so so so much, it worked very well.
 
Learn Excel from Bill Jelen

Understanding data is crucial, and the easiest place to start is with Microsoft Excel.

Forum statistics

Threads
1,151,589
Messages
5,765,313
Members
425,272
Latest member
Umba

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