Creating a Game in Excel...Have a Range & If statement question

mike30549

New Member
Joined
Feb 7, 2015
Messages
2
I have several Sheets involved but I'll have Sheet 2 Active. When I'm on "Sheet 2" I need to know when cell ("C14") becomes active with an IF statement I'm guessing. Once it becomes active, I then need to know if the string in cell ("B2") on Sheet 1 = "Fighter" then I want to insert "some wording regarding the fighter here" in cell ("C14") on Sheet 2. IF it's not "Fighter"then is it "Mage"? If so then insert "some wording regarding the mage here".

This is short hand for example.

if cell C14 on Sheet 2 is active then
check cell B2 on Sheet1, is text = "Fighter"? Then
"You are brave and use a sword"
if Else is cell B2 on Sheet1 = "Mage"? Then
"You cast spells"
etc..

I need to know how to code this in VBA. I've spent hours searching and trying various code but can't get it right. Thanks ahead of time.
 
Last edited:

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Hi and Welcome to MrExcel,

You can do that with an Event procedure.

Copy the code below into the Sheet Code Module of Sheet 2.
(Right-Click on the sheet tab for Sheet 2 > View code to get to that module)

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

 Dim sText As String
  
 If Target.Address = "$C$14" Then
   Select Case Sheets("Sheet 1").Range("B2").Value
      Case "Fighter"
         sText = "You are brave and use a sword"
      Case "Mage"
         sText = "You cast spells"
      Case Else
         'clear any previous value in C14
         sText = ""
   End Select
   Application.EnableEvents = False
   Me.Range("C14").Value = sText
   Application.EnableEvents = True
 End If
End Sub

Check that your actual sheet name matches the name in the code ("Sheet 1" vs "Sheet1")
 
Upvote 0

Forum statistics

Threads
1,216,041
Messages
6,128,467
Members
449,455
Latest member
jesski

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