PDA

View Full Version : [SOLVED:] Problem Word Wrapping VBE Code



Aaron719
01-04-2014, 03:25 PM
Here's my lines of code:

ElseIf (Month(DateAdd("d", 14, dVal)) = yVal And Day(DateAdd("d", 14, dVal)) = xVal) Or (Month(DateAdd("d", 14*2, dVal)) = yVal And Day(DateAdd("d", 14*2, dVal)) = xVal) Or " _
& "(Month(DateAdd('d', 14 *3, dVal)) = yVal And Day(DateAdd('d', 14 * 3, dVal)) = xVal) Or (Month(DateAdd('d', 14 * 4, dVal)) = yVal And Day(DateAdd('d', 14 * 4, dVal)) = xVal) Then


So I want to wrap the line of code above using " _ & " but I got an error saying "Invalid Expression" with the first set of double quotes around the letter d on the second line (Month(DateAdd('d', 14 *3, dVal)). So I changed it to a single quote (as shown), not sure if the code will still work using single quotes there because I now get a different error. The new error says I'm missing a 'Then' and places my cursor after the word 'Then'. Anyone see something wrong?

As a side note I have about 10 lines that look like the above. anyway to maybe clean that up by setting parts of it equal to a label and replacing the code with that label? My only problem is that there is one number that changes in each statement between the OR's; ('d', 14 * 3, dVal)

Thanks a lot

GTO
01-04-2014, 03:42 PM
Not Tested - Try:


ElseIf (Month(DateAdd("d", 14, dVal)) = yVal And Day(DateAdd("d", 14, dVal)) = xVal) _
Or (Month(DateAdd("d", 14 * 2, dVal)) = yVal And Day(DateAdd("d", 14 * 2, dVal)) = xVal) _
Or (Month(DateAdd("d", 14 * 3, dVal)) = yVal And Day(DateAdd("d", 14 * 3, dVal)) = xVal) _
Or (Month(DateAdd("d", 14 * 4, dVal)) = yVal And Day(DateAdd("d", 14 * 4, dVal)) = xVal) Then


In short, you have an unneeded double-quote at the end of the first line (and another one near the beginning of the second line). My bet is when it turned red initially, you made it worse? Anyways, the start of the problem is the ampersand being included. The ampersand is really for String concatenation. Your code has no strings, so kaboom!

Hope that helps,

Mark

Aaron719
01-04-2014, 05:58 PM
Perfect. Thanks a lot GTO!

GTO
01-04-2014, 10:05 PM
Glad to help and that it worked :thumb