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

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
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.
 
Upvote 0
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
 
Upvote 0
Solution
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 :)
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,214,584
Messages
6,120,385
Members
448,956
Latest member
JPav

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