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,9941 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
95.4k9 gold badges58 silver badges99 bronze badges
Выдаёт ошибку Expected: expression
в строке
Range("F1").DataSeriesRowcol := xlColumns,Type:=xlLinear,Step:=x_шаг,Stop:=x_пз,Trend:=False
-
Вопрос заданболее трёх лет назад
-
3493 просмотра
Присваиваете свойству кучу параметров, будто функцию вызываете…
Может лучше так — Range(«F1»).DataSeriesRowcol xlColumns,Type:=xlLinear,Step:=x_шаг,Stop:=x_пз,Trend:=False
Пригласить эксперта
Никита, здравствуйте.
Между методом DataSeries и его аргументом Rowcol надо поставить пробел.
Ссылка на официальную справку Микрософт ЗДЕСЬ.
Update: не видел, что в комментарии к своему ответу rosperitus уже озвучил про пробел.
-
Показать ещё
Загружается…
04 июн. 2023, в 01:35
1500 руб./за проект
04 июн. 2023, в 01:25
40000 руб./за проект
03 июн. 2023, в 23:42
1500 руб./за проект
Минуточку внимания
Вот код
Код |
---|
Sub name() Dim cell1 As Integer Dim cell2 As Integer Set cell1 = 10 Set cell2 = 6 Dim text1 As String Dim text2 As String Dim rename1 As Integer Set rename1 = 0 Dim rename2 As Integer Set rename2 = 0 Do Set text1 = Workbooks("РАСЧЕТ КВАРТИРЫ -Корпус N сек1.xlsm").Worksheets("ЛИМИТКА КNС1").Cells(2, cell1).Value Set cell2 = 6 Set rename2 = 0 Do Set text2 = Workbooks("Материалы.xlsx").Worksheets("ЛИМИТКА К2С1").Cells(2, cell2).Value If text1 = text2 Then Set rename2 = 1 End If Set cell2 = cell2 + 1 Loop While Len(text2) > 0 If rename2 = 0 Then Set rename1 = rename1 + 1 End If Set cell1 = cell1 + 1 Loop While Len(text1) > 0 MsgBox (CStr(rename1)) End Sub |
Выдаёт ошибку Expected Expression. Что не так?
The Expected: expression compile error means that while trying to compile the line, things went haywire because the compiler was expecting to find an expression but found nothing. This error happens if you leave one or more dangling commas at the end of a statement.
For example, the MsgBox statement in Figure 12-5 generated the compile error shown in that same figure. If you look closely, you might also notice that the closing parenthesis in the code is highlighted. The compile error is trying to help out by highlighting the place where it ran into the problem.
Figure 12-5:
Sample Expected: expression compile error.
Figure 12-5:
Sample Expected: expression compile error.
The problem with the line of code is that last comma, just to the left of the closing parenthesis. You use a comma only when you’re about to type another expression into the list of arguments. In other words, while compiling that line of code, the compiler saw that last comma, expecting to find some expression after that comma, but instead found a closing parenthesis.
One solution to the problem would be to get rid of that last comma, as follows:
Answer = MsgBox(«Hello World», vblnformation)
Or, you can leave the comma but add the argument that belongs in that spot. For example, in the MsgBox statement, the third argument is the title to show in the message box. To make that title read as Test, just go ahead and make that word the third argument (after the last comma), as follows:
Answer = MsgBox(«Hello World», vbInformation,»Test»)
Continue reading here: Dealing with Logical Errors
Was this article helpful?
Hi guys I am really stuck on this error code, Expression expected? It is on line 33 and 46
Wow the formatting really got messed up when I pasted it here sorry but the error is highlighted below
Sub Main()
‘Declarations
Dim intRentalDays
As Integer = 0
Dim dblRentalFee
As Double = 2.0
Dim intDaysLate As
Integer = 0
Dim dblLateFees As
Double = 1.5
Dim intLateCharges
As Integer = 0
Dim intTotalDue As
Integer = 0
‘Get DaysRented
getRentalDays(intRentalDays)
‘Calculate IfLate
calculateIfLate(intRentalDays)
‘Calculate Yes
CalculateYes(intRentalDays, intDaysLate, dblLateFees, intLateCharges, dblRentalFee, intTotalDue)
‘Calculate No
CalculateN0(dblRentalFee, intTotalDue)
‘Display Total
displayTotal(dblRentalFee, intTotalDue)
terminateProgram()
End Sub
Private Sub getRentalDays(ByRef intRentalDays
As Integer)
Console.Write(«How many days rented? «)
Console.WriteLine()
End Sub
This is where the “expression expected error is
If intRentalDays > 3
Then
CalculateYes(ByVal intRentalDays As Integer,
ByVal intDaysLate As Integer,
ByVal dblLateFees As Double,
ByVal intLateCharges As Integer,
ByVal dblRentalFee as Double,
ByVal intTotalDue As Integer)
Else
CalculateN0(ByVal dblRentalFee As Double,
ByVal intTotalDue As Integer)
End
If
End Sub
Private Sub CalculateYes(ByVal intRentalDays
As Integer,
ByVal intDaysLate As
Integer, ByRef dblLateFees
As Double, ByRef intLateCharges
As Integer,
ByVal dblRentalFee As
Double, ByRef intTotalDue
As Integer)
intDaysLate = intRentalDays — 3
Console.Write(«Your DVD is late»)
intLateCharges = CInt((intDaysLate * dblLateFees))
Console.Write(«Your late fees are « & intLateCharges)
intTotalDue = CInt((dblRentalFee + intLateCharges))
End Sub
Private Sub CalculateN0(ByVal dblRentalFee
As Double,
ByRef intTotalDue As
Integer)
intTotalDue = CInt(dblRentalFee)
Console.Write(«Thank you for returning on time.»)
End Sub
Private Sub displayTotal(ByVal dblRentalFee
As Double,
ByRef intTotalDue As
Integer)
Console.WriteLine(«Your rental fee is « & dblRentalFee)
Console.WriteLine(«Your total due is « & intTotalDue)
End Sub
Private Sub terminateProgram()
Console.WriteLine()
Console.Write(«Press enter key to terminate the program.»)
Console.Read()
End Sub
End
Module