Problem with Case statement

Rhythmical

New Member
Joined
Jun 8, 2011
Messages
3
Hello,

I'm having trouble with a VB code I'm trying to use. Basically I have two columns one with the data the other without. The data in the left had side is a series of numbers separated in phone number format. I need the code to go down through the rows and test the data against certain criteria. If it finds a match I need it to paste into the right hand column.

Any help you could provide would be great! I can not work out why below does not work?

Code:
Sub Sell()
Dim myCell As Range

For Each myCell In Range("C2:C1859")
    With myCell.Offset(0, 1)
        Select Case myCell.Value


     Select Case myCell.Value

          Case Is = "02 8756 0"
                
                .Value = "Aspect Bush"
              
          Case Is = "02 8756 1"

              .Value = "Aspect Bush"

          Case Is = "03 8634 0"

              .Value = "800 Bourke"

          Case Is = "03 8634 1"

              .Value = "800 Bourke"

          Case Is = "03 8634 2"

              .Value = "800 Bourke"
              
          Case Is = "03 8634 3"

              .Value = "800 Bourke"
              
          Case Is = "03 8634 4"

              .Value = "800 Bourke"
              
          Case Is = "03 8634 8"

              .Value = "800 Bourke"
              
          Case Is = "03 8641 0"

              .Value = "500 Bourke"
              
          Case Is = "03 8641 1"

              .Value = "500 Bourke"
              
          Case Is = "03 8641 2"

              .Value = "500 Bourke"
              
          Case Is = "03 8641 3"

              .Value = "500 Bourke"
              
          Case Is = "03 8641 4"

              .Value = "500 Bourke"
              
          Case Is = "03 8641 5"

              .Value = "500 Bourke"
              
          Case Is = "03 8641 7"

              .Value = "Aspect 120"
              
          Case Is = "03 8641 8"

              .Value = "Aspect 383"
              
          Case Is = "03 8641 9"

              .Value = "Aspect 383"
              
          Case Is = "03 9277 8"

              .Value = "Aspect 383"
              
         Case Is = "03 9277 9"

              .Value = "Aspect 383"

         Case Else

              .Value = "0"
             
    End Select

End With

Next myCell

End Sub
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
You have a superfluous Select Case

Code:
For Each myCell In Range("C2:C1859")
    With myCell.Offset(0, 1)
        Select Case myCell.Value    '<--------Here


     Select Case myCell.Value

          Case Is = "02 8756 0"
 
Upvote 0
You have a superfluous Select Case

Code:
For Each myCell In Range("C2:C1859")
    With myCell.Offset(0, 1)
        Select Case myCell.Value    '<--------Here


     Select Case myCell.Value

          Case Is = "02 8756 0"

Thanks dave3009.

I got rid of that but still no good. Any other ideas?
 
Upvote 0
Finally got it working. realized every time I changed something I didn't press the play button. I'm such an idiot
 
Upvote 0
Hi

Perhaps -

Code:
    Select Case myCell.Value
 
          Case Is = 0287560, 0287561
 
              .Value = "Aspect Bush"
 
          Case Is = 0386340, 0386341, 0386342, 0386343, 0386344, 0386348
 
             .Value = "800 Bourke"
 
          Case Is = 0386410, 0386411, 0386412, 0386413, 0386414, 0386415
 
              .Value = "500 Bourke"

etc, etc...

hth

Edit - You solved it in the meantime.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,834
Members
452,947
Latest member
Gerry_F

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