I am working on some homework and I can’t figure out why my code won’t work. The assignment is to request a name then respond in red text in B10.
Here is my code:

Any help would be great- Thanks!
asked Apr 7, 2014 at 1:21
2
This error comes from the line With RAnge("b10").Font.ColocarIndex = 3, With supose to be used only to objects (not expressions)
sName = Application.InputBox(Prompt:="Please enter your name.", Type:=2)
With Sheets("MyNewSheet").Range("B10")
.Font.ColorIndex = 3
.Value = sName
End With
answered Apr 7, 2014 at 2:18
![]()
Roger BarretoRoger Barreto
1,9541 gold badge16 silver badges21 bronze badges
Consider:
Sub qwerty()
Sheets("MyNewSheet").Activate
With Range("B10")
.Font.ColorIndex = 3
strName = Application.InputBox(Prompt:="Please enter your name.", Type:=2)
.Value = strName
End With
End Sub
answered Apr 7, 2014 at 2:09
![]()
Gary’s StudentGary’s Student
94.9k9 gold badges58 silver badges97 bronze badges
I realise that the use of VBA in modifications and customisations is something that needs to be carefully considered with Microsoft Dynamics GP 2013 including a Silverlight based Web Client which cannot use VBA. I had a requirement from a client for a modification to the Debtor Enquiry (Customer Inquiry to the Americans reading) to include the sum of the displayed transactions on the window and as this was a small client with GP installed locally on each PC there is no requirement for the web client, I felt able to perform this change using Modifier using some VBA.
I added the required fields to the VBA project but encountered an error message when writing the VBA code to concatenate the fields into the SQL statement I was going to use to get the data;
Microsoft Visual Basic: Compile error: Expected: expression
It took me a few minutes to realise that the cause of the error is that To is a restricted keyword in VBA. Once I had realised this, I was able to quickly work around the error by updating the code to refer to the field To with more accuracy;

The red ringed text shows how I got VBA to accept the variable. The Me refers to the Debtor Enquiry window and specifies that To is not a keyword but a child object of the window.
- Remove From My Forums
-
Question
-
Hello Folks
I am a newbee when it comes to writing lines in a programming language.
I was given a task of writing a condition for a project.
I was using the «OR» operator and it gives me an Expression Expected Error. Amusingly, the error is in different versions of Visual Basic Express Edition.
In 2008, there is no error. But in VB 2005, i get the Expression Expected Error, Was wondering if it was the version or my own fault in writing. Please advise.
If
mventry(«something»).IsPresent
AndAlso mventry(«something»).StringValue.ToLower
= «something»
Or
If(mventry(«something»).Values.Contains(«something»))
Then
Answers
-
Judging by the code you have an extra If — but the code layout is poor and there might be some missing.
I’ve found the best way to post code is to copy and paste it into Notepad, then copy and paste from Notepad — the code button here often seems to mess up code copied directly from VB.
Regards David R
—————————————————————
Every program eventually becomes rococo, and then rubble. — Alan Perlis
The only valid measurement of code quality: WTFs/minute.-
Proposed as answer by
Tuesday, April 19, 2011 5:47 AM
-
Marked as answer by
Mike FengModerator
Wednesday, April 27, 2011 9:29 AM
-
Proposed as answer by
-
I agree — you probably should just drop the second «If» — you don’t need it with «Or» expressions. Also, consider using the OrElse operator — it is a short-circuiting logical operator just like the AndAlso you are using that will only evaulate
the second condition if the first one is False. There are few ordinary cases where an Or is preferred to an OrElse. Here’s what your line would look like this way (assuming we’ve interpreted it correctly):If (mventry("something").IsPresent AndAlso mventry("something").StringValue.ToLower = "something") OrElse (mventry("something").Values.Contains("something")) Then-
Proposed as answer by
Mike FengModerator
Tuesday, April 19, 2011 5:47 AM -
Marked as answer by
Mike FengModerator
Wednesday, April 27, 2011 9:29 AM
-
Proposed as answer by
-
If you would like to post, please check out the MrExcel Message Board FAQ and register here. If you forgot your password, you can reset your password.
-
#1
Hi, I keep getting the error messgae «compile error: expected expression»
VBA also highlights :=
Sub Solve()
SolverOk.SetCell:= «$I$15″, MaxMinVal:=1, ValueOf:=»0″, ByChange:=»$I$3:$I$12»
SolverSolve UserFinish:=True
End Sub
Any ideas? Thanks in advance. 😀
Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
shg
MrExcel MVP
-
#2
Welcome to the board.
Replace the dot after SolverOK with a space.
-
#3
Oh it worked. Thanks a lot. 😀
shg
MrExcel MVP
-
#4
You’re welcome, good luck.
- Threads
- 1,186,141
- Messages
- 5,956,143
- Members
- 438,235
- Latest member
- robbfisher83
Tags for this Thread
|
|


