Select cell based on value of another cell

1Marte

New Member
Joined
Apr 9, 2011
Messages
9
My problem is probably very simple...I'm about to pull my hair out! I am using Excel2007.
I want to use the value that is in one cell to determine which of two cells to select in the worksheet. No copy, delete, just SELECT.
When I hover over the code it has the correct value, but the code doesnt work.
The bad code follows. I left the comments in so you can see what I've tried. nothing works.
THANK YOU in advance for any help. I have never posted before in my life, I have always found answers on this forum.

Sub FigFedWHcht()
'select the correct chart (Married or Single)
Sheets("Chart").Select '.Range("P6").Select
Dim rng As Range
'Set MCht = Sheet2.Range("B11")
'Set SCht = Sheet2.Range("R11")
Set rng = Sheet2.Range("P6")
With rng
'rng = rng.Value
Select Case rng
Case M
'MCht.Select
'Sheet2.Range("B11").Select
Sheet2.Range("FirstCellMarriedChrt").Select
Case S
'SCht.Select
'Sheet2.Range("R11").Select
Sheet2.Range("FirstCellSingleChrt").Select
'Case Else
' MsgBox ("There seems to be a problem") 'FOR TESTING
' GoTo xit
End Select
End With
Call FedFindResult
xit:
End Sub
 
This worked for me last night before I went to bed. I think I have a couple of strands of hair left. I may have to just write code to always select Married as all my employees are married. Payroll was due yesterday. and I'm getting tired of code. I just wanted to confirm that I wasnt crazy. I'm totally self taught (about 6 years now). There must be something else in the background that is preventing this from working properly.
 
Upvote 0

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Just a thought...

Is it possible Application.EnableEvents could be turned off.

Open up the immediate window (Ctrl + G) >> Application.EnableEvents = True >> Enter
 
Upvote 0
Sorry to say, that didnt work either. I usually try not disable events if possible as i forget to write code to turn them back on and get into problems. Its my practice not to use application.enable events = false.
Just a quirk of mine.
 
Upvote 0
I have learned how to post code on this forum. and how to open the immediate window quickly. I dont use the immediate window as I cant wrap the concept of its use around my brain. I read and read, sometimes it sticks, sometimes....
 
Upvote 0
Well I sure don't know what else it could be.

Did you try the code I attached or you just wanted confirmation?

You said it worked last night, but I noticed your M and S are not enclosed in "".
 
Upvote 0
I've enclosed them, unenclosed them. I pasted your code in. Nothing is working. Its got to be code running before this fires. I am trying to write this "masterpiece" using the column of the activecell.row , instead of selecting individual employees. That way I dont have to write code for "Sean" , same similar code for "Marte", etc. It works in what ever employees row I am working with. I got the code idea from this forum. Anytime I solve a problem or clear up messy code its with the know-how I walk away from here.
for example : Range("B" & (Activecell.row)) has really been a help. I went from 70 pages of written code for 3 employees to 10 pages.
I hope I didnt dent your armor of confidence. I'm walking away happy. I thank you so much for your help. You made my first experience at posting very pleasant.
THANK YOU JEFF!
 
Upvote 0

Forum statistics

Threads
1,224,592
Messages
6,179,789
Members
452,942
Latest member
VijayNewtoExcel

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