Select Case Statements........

MAButler

New Member
Joined
Mar 30, 2011
Messages
35
I have this set up and it works fine........ but the value that it puts into column 8 (1940**) changes from time to time, and i have to be there to change the file. Can the reference to a cell (Sheet2 (Info) C6) be put in there and then all the idiots have to do is type the new number in that cell.......

Code:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Column = 1 Then
        Select Case Target.Cells.Value
        Case 4505
            Target.Offset(0, 8).Value = 194069
        Case 4513
            Target.Offset(0, 8).Value = 194079
        Case 4521
            Target.Offset(0, 8).Value = 194089
        Case 4548
            Target.Offset(0, 8).Value = 194099
        Case Else
            Target.Offset(0, 8).Value = 0
        End Select
    End If
End Sub
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
would something like

Target.Offset(0, 8).Value = sheets("sheet1").Range("A1").value

work ?

I haven't actually tested it
 
Upvote 0
I tried everything with this and struggled to get anything to show untill I
changed to an if statement, then it seems to work !!! I don't know why

Code:
  If Target.Column = 1 Then
      If Target.Value = 4505 Then
            Target.Offset(0, 8).Value = Sheet2.Cells(1, 1)
 
Upvote 0
Code:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Column = 1 And Target.Cells.Count = 1 Then
        Select Case Target.Cells.Value
        Case 4505
            Target.Offset(0, 8).Value = Sheet2.Cells(1, 1)
        Case 4513
            Target.Offset(0, 8).Value = Sheet2.Cells(2, 1)
        Case 4521
            Target.Offset(0, 8).Value = Sheet2.Cells(3, 1)
        Case 4548
            Target.Offset(0, 8).Value = Sheet2.Cells(4, 1)
        Case Else
            Target.Offset(0, 8).Value = Sheet2.Cells(5, 1)
        End Select
    End If
End Sub

This works for me. I have sheet2 set up with the 5 numbers in column A. I added the second condition to the if to keep it from running if more than one cell is selected, like if you are trying to delete a block of cells.
 
Upvote 0
Thanks, it works a treat. Made a slight adjustment.......

Code:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Column = 1 And Target.Cells.Count = 1 Then
        Select Case Target.Cells.Value
        Case Sheet2.Cells(5, 3)
            Target.Offset(0, 8).Value = Sheet2.Cells(6, 3)
        Case Sheet2.Cells(5, 4)
            Target.Offset(0, 8).Value = Sheet2.Cells(6, 4)
        Case Sheet2.Cells(5, 5)
            Target.Offset(0, 8).Value = Sheet2.Cells(6, 5)
        Case Sheet2.Cells(5, 6)
            Target.Offset(0, 8).Value = Sheet2.Cells(6, 6)
        Case Else
            Target.Offset(0, 8).Value = Sheet2.Cells(6, 7)
        End Select
    End If
End Sub
 
Upvote 0
Could throw in a little With statement action.

Code:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
    With Target
        If .Column = 1 And .Cells.Count = 1 Then
            Select Case .Cells.Value
            Case 4505
                .Offset(0, 8).Value = Sheet2.Cells(1, 1)
            Case 4513
                .Offset(0, 8).Value = Sheet2.Cells(2, 1)
            Case 4521
                .Offset(0, 8).Value = Sheet2.Cells(3, 1)
            Case 4548
                .Offset(0, 8).Value = Sheet2.Cells(4, 1)
            Case Else
                .Offset(0, 8).Value = Sheet2.Cells(5, 1)
            End Select
        End If
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,574
Messages
6,179,634
Members
452,934
Latest member
Jdsonne31

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