PDA

View Full Version : Solved: One sheet dependent on input on another?



blackie42
03-31-2008, 03:33 AM
Hi

Wasn't sure how to title this.

What I want to do is have a cell in sheet1 return a certain value dependent on whats input to a cell on another sheet. Not sure whats the best way to do it.

e.g.

If cell A1 on sheet2 = Bank1 then cell A1 on sheet1 = "00001111"
If cell A1 on sheet2 = Bank2 then cell A1 on sheet1 = "00002222"

Could use a lookup table but can it be done in VBA?

thanks for any help

Bob Phillips
03-31-2008, 03:36 AM
Appropriate is sheet2 here



Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "A1" '<== change to suit

On Error GoTo ws_exit
Application.EnableEvents = False

If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target

Select Case .Value

Case "Bank1": Worksheets("Sheet1").Range("A1").Value = "00001111"
Case "Bank2": Worksheets("Sheet1").Range("A1").Value = "00002222"
'etc
End Select
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub


This is worksheet event code, which means that it needs to be
placed in the appropriate worksheet code module, not a standard
code module. To do this, right-click on the sheet tab, select
the View Code option from the menu, and paste the code in.

blackie42
03-31-2008, 08:13 AM
Thanks very much for your help XLD - much apprciated

Jon