IF and ELSEIF Statement with condition of a cell is selected

AndyVoClosser

New Member
Joined
Oct 30, 2023
Messages
9
Office Version
  1. 365
Platform
  1. Windows
Hi Community. I need you help to fix this Marco. I am trying to show data based on the condition of a cell is selected. Below is my code. Thank you so much.

Sub ShowData()

If ActvieSheet.Range("A2").Select = True Then
Sheets("Chart Data").Select
Range("B2:B6").Select

ElseIf ActvieSheet.Range("B2").Select = True Then
Sheets("Chart Data").Select
Range("D2:D6").Select


ElseIf ActvieSheet.Range("C2").Select = True Then
Sheets("Chart Data").Select
Range("E2:E6").Select
End If
End Sub
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Try changing how you are checking each one.

Instead of doing this:
VBA Code:
If ActvieSheet.Range("A2").Select = True Then
try this method:
VBA Code:
If Not Intersect(ActiveCell, Range("A2")) Is Nothing Then
 
Upvote 0
Solution
Try changing how you are checking each one.

Instead of doing this:
VBA Code:
If ActvieSheet.Range("A2").Select = True Then
try this method:
VBA Code:
If Not Intersect(ActiveCell, Range("A2")) Is Nothing Then
Thank you, it works well. I have another problem, could you help me check it. I have a series chart with 5 points. Now I want if I select points(1), it will show the data of points(1), if I select point(2), it will show the data of points(2),...., to points(5). Could you help me with this issue. I appreciate you.
 
Upvote 0
Thank you, it works well. I have another problem, could you help me check it. I have a series chart with 5 points. Now I want if I select points(1), it will show the data of points(1), if I select point(2), it will show the data of points(2),...., to points(5). Could you help me with this issue. I appreciate you.
That is a totally different question, and should be asked in a new thread of its own.
(I probably would not be able to help anyway, as I know very little about charts - I never use them!)
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,329
Members
452,635
Latest member
laura12345

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