Excel

TheSmallman.com

an XL ideas Lab

Dashboards VBA
  • Home
  • Dashboards
    • Tips & Tricks
    • Charts
    • Modelling
    • Infographics
    • VBA
  • Shop Dashboards
    • Power Pivot a User Guide
    • Excel Dashboard Course
    • Advanced Dashboard Course
    • Financial Modelling Course
    • Excel VBA Course
  • Blog
  • About
Menu

Excel Dashboards VBA

Street Address
City, State, Zip
Phone Number
an XL ideas Lab

Your Custom Text Here

Excel Dashboards VBA

  • Home
  • Dashboards
  • Excel Tips
    • Tips & Tricks
    • Charts
    • Modelling
    • Infographics
    • VBA
  • Shop Dashboards
  • PowerPivot
    • Power Pivot a User Guide
  • Courses
    • Excel Dashboard Course
    • Advanced Dashboard Course
    • Financial Modelling Course
    • Excel VBA Course
  • Blog
  • About

Move Sheets Based on a List with VBA

April 12, 2015 Marcus Small

I recently had a problem, I had a summary sheet which was calculating all of the data between a beginning sheet and an end sheet.  However, the sheets in-between the begin and end tabs were changing based on a selection from a list.  What I wanted was the flexibility to move the sheets in and out based on what had been selected in this list.  The summary will be updating once the procedure runs and the end result needs to be flexible.

Once again we will need VBA to produce a result.  Firstly I will move the end sheet next to the start sheet.  Then it is just a matter of putting all of the sheets inbetween these two tabs.

The data in the list is a sample of what will be pushed inbetween my Beginning and End tabs. My example file has 6 sheets, these are:

NSW
TAS
QLD
SA
WA
VIC

The general idea is if NSW, TAS and QLD appear in the list above then after the procedure has run the file will look as follows.

Notice how only the sheets from our drop down are included between the two blue sheets.  The ramifications are in the summary sheet where only the data inside the blue tabs will be summariesd.  SA, WA and VIC in the above example are omitted.

The following is the VBA coding to achieve the task. 

Sub Move() 'Excel VBA code to move sheets inside Begin and End tabs
Dim i As Integer

Sheet5.Move after:=Sheet2

   For i = 1 To Range("B" & Rows.Count).End(xlUp).Row - 10
      Sheets(CStr(Sheet1.Range("B" & i + 10))).Move after:=Sheet2
   Next i
End Sub

As the list starts in row 11 I will need to take 10 lines off the dynamic upper bound range of the loop.  This will give the code the abilty to pick up every sheet in the loop.

The Excel file attached allows you to check the workings of the above procedure.

MoveSheets.xls

← Excel Dashboard by Department and RegionEvaluate and Filter in Harmony →

Featured Posts

Excel Dashboards: Tracking a Crisis

Excel Dashboards: Tracking a Crisis
April 14, 2020

Recent Posts

Populating an Excel Table from a Range of Cells with VBA

Populating an Excel Table from a Range of Cells with VBA June 12, 2025

Fuzzy Distribution with Randbetween

Fuzzy Distribution with Randbetween May 21, 2025

Add Minimum and Maximum for Chart in Cells

Add Minimum and Maximum for Chart in Cells March 12, 2025

Inflation Over Multiple Years in a Single Cell

Inflation Over Multiple Years in a Single Cell January 10, 2025

Hubspot Dashboard

Hubspot Dashboard October 3, 2024

Monthly Dashboard With Supporting Metrics

Monthly Dashboard With Supporting Metrics September 25, 2024

Excel Show Missing Sheet Tabs

Excel Show Missing Sheet Tabs July 29, 2024

Run Macro Overnight Automatically

Run Macro Overnight Automatically June 24, 2024

Split File into Parts and Save to Directory

Split File into Parts and Save to Directory April 20, 2024

Most Popular Author

Most Popular Author December 14, 2023

 

Follow US:

 
 

MarcusSmall@thesmallman.com

 

TheSmallman.com - Making your small systems hum...
© Copyright 2013-2024 theSmallman.com All Rights Reserved.