Sometimes you need to organize the spreadsheet’s variables before creating a chart using them. This is similar to when creating a scatter plot. The independent variable is supposed to be on the left, while the dependent variable is supposed to be on the right. In this article, you will learn and see how to switch the X and Y-axis in Excel using two easy ways.
Download Practice Workbook
You may download the following Excel workbook for better understanding and practice yourself.
2 Handy Ways to Switch between X and Y-Axis in Excel
You have more freedom to change the chart axis when you change the axis choice. Additionally, by doing it in this manner, you may keep your sheet’s data unchanged. Therefore, these are two straightforward methods for changing the axis in Excel charts. In the given data set, we arrange the data in order to switch the X and Y-axis in Excel. Here, we will show you how to switch the X and Y-axis in Excel using Editing Data Series and applying VBA codes.
1. Editing Data Series to Switch X and Y-Axis in Excel
Here, we will first create a Scatter Chart and then switch the X and Y-axis in Excel. A scatter graph shows two connected quantitative variables. You then input two sets of numerical information into two different columns. The following steps are given below.
Step 1:
- First, select the Sales and Profits columns.
Step 2:
- Go to the Insert tab.
- Click on the Scatter chart icon.
Step 3:
- Select the desired option from the Scatter Charts, Here, we will select the first option, which we have marked with a red color rectangle.
Step 4:
- Finally, we will show the given result on the Scatter Chart.
Step 5:
- Right-click on the Scatter Chart and click on the Select Data command.
Step 6:
- Click on the Edit option.
Step 7:
- Now, write down the X values in the Y series and Y values in the X series.
- Click OK.
Step 8:
- Finally, we will see the following graph where the X and Y-axis will be switched.
Read More: How to Add X and Y Axis Labels in Excel (2 Easy Methods)
2. Applying VBA Code to Switch X and Y-Axis in Excel
Applying VBA code in Excel to switch the X and Y-axis is a very convenient way. We will show you how to generate VBA code in Excel for this given data set. The following steps are given below. Let us consider the following data set to apply a VBA code to switch the X and Y-axis.
Step 1:
- Go to the Developer tab.
- Click on the Visual Basic option.
Step 2:
- A Visual Basic window will open and click on the Insert tab.
- Click on the Module option to create a new Module.
Step 3:
- Here, paste the following VBA codes into the new Module.
Sub switch_axis()
Dim srs As Series
Set Rng = ActiveSheet.Range("C5:D16")
With ActiveSheet.ChartObjects.Add(Left:=Rng.Left, Width:=Rng.Width, Top:=Rng.Top, Height:=Rng.Height)
Chart.ChartType = xlXYScatterLines
.Chart.SetSourceData Source:=Range("C5:C16,D5:D16")
Set srs = .Chart.SeriesCollection.NewSeries
srs.Name = "sales Vs Profits"
srs.XValues = Range("D5:D16")
srs.Values = Range("C5:C16")
End With
End Sub
Step 4:
- Finally, we will see the following Scatter Chart of switching the X and Y-axis using VBA Codes in Excel.
Read More: How to Change X-Axis Values in Excel (with Easy Steps)
Conclusion
In this article, I’ve covered two easy ways to switch X and Y axis in Excel. I sincerely hope you enjoyed and learned a lot from this article. Additionally, if you want to read more articles on Excel, you may visit our website, Exceldemy. If you have any questions, comments, or recommendations, kindly leave them in the comment section below.
Related Articles
- How to add secondary axis in Excel (2 easy ways)
- How to Add Axis Titles in Excel (2 Quick Methods)
- How to Change Axis Labels in Excel (3 Easy Methods)
- Excel Bar Chart Side by Side with Secondary Axis
- How to Add Secondary X Axis in Excel (with Quick Steps)
- How to Add Second Vertical Axis in Excel Scatter Plot (3 Suitable Ways)