vba expressions

linger

New Member
Joined
Mar 26, 2003
Messages
21
hi there,

i have 3 cases that i have to compare using VB. the psuedo code goes like this

case1
X is not equal to 0 & Y is not equal to 0
case 2
X = 0 and Y not equal 0
case 3
X not equal 0 and Y=0

can anyone give me an example of how the VBA code should look like? i've looked at examples in a book but they're very general and simple. thanks

yiling
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
hi here's what i've been working on so far...i've only be learning VBA for the last 4 hours and I'm trying to write this function described above.

Option Compare Database
Option Explicit

Private Sub NullHandlingAvg()
Dim AvgTip As Double
Dim center As Double
Dim edge As Double
center = 4
edge = 3

'test1: center and edge are both not equal null

If center <> 0 And edge <> 0 Then
AvgTip = (center + edge) / 2
Debug.Print "test 1 AvgTip= " & AvgTip


ElseIf center <> 0 And edge = 0 Then
AvgTip = center
Debug.Print "Test 2 AvgTip= " & AvgTip

Else
AvgTip = edge
Debug.Print "Test 3 AvgTip= " & AvgTip

End If

End Sub

ling
 
Upvote 0

Forum statistics

Threads
1,221,558
Messages
6,160,484
Members
451,651
Latest member
Penapensil

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top