VBA code to deal with Shift+Enter

ankita.sethi

Board Regular
Joined
Apr 27, 2011
Messages
58
Hi,

i am writing a code to find a text in a particular row in excel. The problem is that the text exists with Shift+Enter in it twice (manual line break).

The text is "Ave Speed of Answer"; but entered like this:
Ave
Speed
of Answer

I have tried the following:
ASA = Range("A11:Z11").Find("AveSpeedof Answer", Range("A11"), xlValues, xlWhole, xlByColumns, xlNext).Column

Also:
ASA = Range("A11:Z11").Find("Ave" & Chr(11) & "Speed" & Chr(11) & "of Answer", Range("A11"), xlValues, xlWhole, xlByColumns, xlNext).Column

It gives the error "Object Variable or With Block Variable not set". In my experience, this error pops up when it cannot find the text.

Please help!!
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Ankita,

Have you declared the variable "ASA" as range? This error will come if a variable is declared as object.
 
Upvote 0
Yup, Jan is right. Take a look at the following snippet.
Code:
Public Sub Snippet()
Dim sString As String
Dim iColumn As Integer
sString = "Ave" & Chr(10) & "Speed" & Chr(10) & "of Answer"
iColumn = Cells.Find(What:=sString).Column
MsgBox iColumn
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

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