Solved

Excel VBA

Posted on 2014-02-20
10
248 Views
Last Modified: 2014-02-20
Hello,
can you please help,

how do I break this long line into multiple lines.

I tried the (space then _ then enter ) at end of a line, it didn't work,
I tried the (" & _ then enter ) at end of a line, it didn't work,

error, Expected line number or end statement

    Const Fmla1 = "=OR(A2=(""1300"",""1302"",""1303"",""1304"",""1305"",""1310"",""1311"",""1314"",""1315"",""1316"",""1318"",""1320"",""1321"",""1322"",""1323"",""1324"",""1325"",""1326"",""1330"",""1336"",""1338"",""1340"",""1341"",""1345"",""1350"",""1353"",""1355"",""1357"",""1358"",""1360"",""1362"",""1365"",""1370"",""1378"",""1379"",""1380"",""1381"",""1382"",""1385"",""3500"",""3506"",""3507"",""3514"",""3521"",""3528"",""3534"",""3535"",""3542"",""3545"",""3600"",""3601"",""3608"",""3609"",""3610"",""3611"",""3612"",""3613"",""3614"",""3616"",""3624"",""3625"",""3626"",""3627"",""3628"",""3629"",""3630"",""3631"",""3632"",""3637"",""3642"",""3643"",""3648"",""3649"",""3650"",""3651"",""3653"",""3654"",""3655"",""3656"",""3659"",""3660"",""3662"",""3664"",""3665"",""3666"",""3700"",""3702"",""3703"",""3704"",""3705"",""3708"",""3709"",""3710"",""3715"",""3720"",""3725"",""3727"",""3730"",""3735"",""3736"",""3737"",""3738"",""3745"",""3750"",""3751"",""3754"",""3760"",""3761"",""3762"",""3763"" , ""3764"",""3765"",""3766"",""3767"",""3771"",
""3777"",""3778"",""3779"",""3781"",""3785"",""3786"",""3794"",""3795"",
""3796"",""3844"",""3848"",""3851"",""3854"",""3857""))"


thanks
0
Comment
Question by:Wass_QA
  • 5
  • 5
10 Comments
 
LVL 81

Expert Comment

by:zorvek (Kevin Jones)
ID: 39874449
You can't break a constant up with line breaks (space followed by an underscore).

Alternatives: store the value in a cell and load it into a variable or build it in code.

Kevin
0
 
LVL 81

Expert Comment

by:zorvek (Kevin Jones)
ID: 39874463
Building it:

    Dim Fmla1 As String
    Fmla1 = "=OR(A2=(""" & Join(Array(1300, 1302, 1303, 1304, 1305, 1310, 1311, 1314, 1315, 1316, 1318, 1320, 1321, 1322, 1323, 1324, 1325, 1326, 1330, 1336, 1338, 1340, 1341, 1345, 1350, 1353, 1355, 1357, 1358, 1360, 1362, 1365, 1370, 1378, 1379, 1380, 1381, 1382, 1385, 3500, 3506, 3507, 3514, 3521, 3528, 3534, 3535, 3542, 3545, 3600, 3601, 3608, 3609, 3610, 3611, 3612, 3613, 3614, 3616, 3624, 3625, 3626, 3627, 3628, 3629, 3630, 3631, 3632, 3637, 3642, 3643, 3648, 3649, 3650, 3651, 3653, 3654, 3655, 3656, 3659, 3660, 3662, 3664, 3665, 3666, 3700, 3702, 3703, 3704, 3705, 3708, 3709, 3710, 3715, 3720, 3725, 3727, 3730, 3735, 3736, 3737, 3738, 3745, 3750, 3751, 3754, 3760, 3761, 3762, 3763, 3764, 3765, 3766, 3767, 3771, 3777, 3778, 3779, 3781, 3785, 3786, 3794, 3795, 3796, 3844, 3848, 3851, 3854, 3857), """,""") & """))"
    Debug.Print Fmla1

Open in new window


Kevin
0
 

Author Comment

by:Wass_QA
ID: 39874529
Hi Kevin,
can you please show me how ,
I attached the first part of my code.

thanks
sample.txt
0
 
LVL 81

Expert Comment

by:zorvek (Kevin Jones)
ID: 39874538
See code above. It's ready to go.

Kevin
0
 

Author Comment

by:Wass_QA
ID: 39874601
I get error
compile error
constant expression required.

= "=OR(A2=(""" & Join(Array(

thanks
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 81

Expert Comment

by:zorvek (Kevin Jones)
ID: 39874706
Copy the code above as-is. Don't copy parts of it.

Kevin
0
 

Author Comment

by:Wass_QA
ID: 39875280
HI Kevin,
I have the full code,
but I still get an error.

error : run-time error 1004
application-defined or object-defined error

debug on this line
    wksTemp.Range("Y2").Formula = Fmla1

sample 2 attached is the full code.

thanks again.
sample-2.txt
0
 
LVL 81

Accepted Solution

by:
zorvek (Kevin Jones) earned 300 total points
ID: 39875293
Replace the assignment statement with this:

    Dim Fmla1 As String
    Fmla1 = "=OR(A2={""" & Join(Array(1300, 1302, 1303, 1304, 1305, 1310, 1311, 1314, 1315, 1316, 1318, 1320, 1321, 1322, 1323, 1324, 1325, 1326, 1330, 1336, 1338, 1340, 1341, 1345, 1350, 1353, 1355, 1357, 1358, 1360, 1362, 1365, 1370, 1378, 1379, 1380, 1381, 1382, 1385, 3500, 3506, 3507, 3514, 3521, 3528, 3534, 3535, 3542, 3545, 3600, 3601, 3608, 3609, 3610, 3611, 3612, 3613, 3614, 3616, 3624, 3625, 3626, 3627, 3628, 3629, 3630, 3631, 3632, 3637, 3642, 3643, 3648, 3649, 3650, 3651, 3653, 3654, 3655, 3656, 3659, 3660, 3662, 3664, 3665, 3666, 3700, 3702, 3703, 3704, 3705, 3708, 3709, 3710, 3715, 3720, 3725, 3727, 3730, 3735, 3736, 3737, 3738, 3745, 3750, 3751, 3754, 3760, 3761, 3762, 3763, 3764, 3765, 3766, 3767, 3771, 3777, 3778, 3779, 3781, 3785, 3786, 3794, 3795, 3796, 3844, 3848, 3851, 3854, 3857), """,""") & """})"

Open in new window


Kevin
0
 

Author Comment

by:Wass_QA
ID: 39875344
thank you, thank you,
0
 

Author Closing Comment

by:Wass_QA
ID: 39875346
Superb,
thanks
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now