Question

Whats wrong with my vba? Option Explicit Sub problem2() Sheet("Sheet2").Select Dim p As Double, V As...

Whats wrong with my vba?

Option Explicit
Sub problem2()
Sheet("Sheet2").Select
Dim p As Double, V As Double, d As Double, u As Double
Dim rey As Double
Range(“B1”).Select
p = ActiveCell.Value
Range(“B2”).Select
V = ActiveCell.Value
Range(“B3”).Select
d = ActiveCell.Value
Range(“B4”).Select
u = ActiveCell.Value
Function rey(p, V, d, u)
Range(“B6”).Value
If rey >= 0 And rey <= 2100 Then
MsgBox“Laminar Flow”
ElseIf rey > 2100 And rey < 4000 Then
MsgBox“Transitional Flow”
ElseIf rey >= 4000 Then
MsgBox“Turbulent Flow”
ElseIf rey < 0 Then
MsgBox“Error:Reynolds number must be positive”
End If
End Sub
Function rey(p, V, d, u)
rey = (p * V * d) / u
End Function

Homework Answers

Answer #1

Following is the modified code. the code thar I made change is underlined

Option Explicit
Private Sub problem2()
Rem Sheet1("Sheet1").Select
Sheet1.Select
Dim p As Double, V As Double, d As Double, u As Double
Dim r As Double rem rey is a function . so instead or rey , I declare r
Range("B1").Select rem double quotes corrected. delete double quotes and again type from keyboard.
p = ActiveCell.Value   
Range("B2").Select
V = ActiveCell.Value
Range("B3").Select
d = ActiveCell.Value
Range("B4").Select
u = ActiveCell.Value
r = rey(p, V, d, u)    rem to call a function dont write kewword function,and as a function return a rem value store in a variable . r
Range("B6").Value = r
If r >= 0 And r <= 2100 Then
MsgBox "Laminar Flow" rem same double quote problem here. delete and re write double quotes.
ElseIf r > 2100 And r < 4000 Then
MsgBox "Transitional Flow"
ElseIf r >= 4000 Then
MsgBox "Turbulent Flow"
ElseIf r < 0 Then
MsgBox "Error:Reynolds number must be positive"
End If
End Sub

Public Function rey(ByVal p As Double, ByVal V As Double, ByVal d As Double, ByVal u As Double)

rem a function parameter sould be written like above byval/byref parameter as datatype
rey = (p * V * d) / u
End Function

rem call to sub problem2()

Private Sub CommandButton1_Click()
Call problem2
End Sub

rem ---------------------------------------------------------------------

rem output screen

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT