PDA

View Full Version : Select Case Statements; Homework



ladeda16
04-05-2008, 04:47 PM
So, it seems that i have a problem with this code. I am trying to get a information from one column to match it with another column to get me a result.

For example,

I have a Cake on Range("D5") and From Range("B5:B19") i have a cake that consist of 5 cakes. So i want to put that value 5 into Range("E5")

B5 Cake
B6 Cake
B7 Cake
B8 Cake
B9 Cake
B10 Muffin
B11 Muffin
B12 Bread
B13,B14..... etc

D5 Cake

E5 5

So, I am requesting how many Cakes are there from B5:B19, And D5 is the name # of Cake, So E5 i put 5


Function GetCakeRow(strCake As String) As Integer

Select Case strCake
strCake = Range("D5:D23")

Case Is = Range("F5").Value
strCake = 5
Case Is = Range("F6").Value
strCake = 4
Case Is = Range("F7").Value
strCake = 3
Case Is = Range("F8").Value
strCake = 4
Case Is = Range("F9").Value
strCake = 3
Case Else
Range("F5:F9").Value = 0

End Select

End Function

mdmackillop
04-06-2008, 01:19 AM
Hi Ladeda,
Please make it clear that these are homework questions. We can give guidance but not solutions. "Proper" solutions are likely to be in advance of your course , so your are better to work these out for yourself.

This does not merit a VBA solution, unless specifically asked for.

You ask how many cakes? That implies that there is a need to count them.