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

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
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,215,149
Messages
6,123,311
Members
449,095
Latest member
Chestertim

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