vba help - break line

Mallesh23

Well-known Member
Joined
Feb 4, 2009
Messages
976
Office Version
  1. 2010
Platform
  1. Windows
Hi Team,

I am Unable to break lenghty code into next line, suing & _

VBA Code:
Sub Break_Line()

Dim s As String
s = "ABC USD 145,356"
if instr(s,"JAN")>0 & _   'Error here unable to break the line. 
    OR instr(s,"USD") > 0 then
    dict.Add s, s
End If

End Sub


Thanks
mg
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
You cannot split a quoted text string in the middle like that. What you have to do is put an end quote after the first part of the text, then an ampersand, then your space/underline, then put another quote mark in front of the second part of the text. So...
VBA Code:
if instr(s,"JAN")>0" & _
    "OR instr(s,"USD") > 0 then
Note: I cannot tell from your text whether I dropped a space character between the two text substrings or not, so you may have to put one in if I did.
 
Upvote 0
Hi Rick,

Thanks for your information very nice.
I tried different combination in the code suggested by you, its not working for me.

unable to fix it. Can you try from your end plz



Thanks
mg
 
Upvote 0
Just remove the & from your code.
 
Upvote 0
What I posted about breaking text strings in the middle was correct BUT, now that I look more closely, IT DOES NOT APPLY to your problem. The problem was that you tried to use an ampersand (used to join text strings) on two stand-alone functions which are not text strings. Simply remove the ampersand...
VBA Code:
if instr(s,"JAN")>0 Or _
    instr(s,"USD") > 0 then
 
Last edited:
Upvote 0
Hi Rick and Fluff,

it worked ! Really I learned something interesting here tricky one. thanks for your help (y) ?


Thanks
mg
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,054
Messages
6,122,893
Members
449,097
Latest member
dbomb1414

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