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

Union An Excel Range and Transpose

March 23, 2016 Marcus Small

I was asked by a colleague to transpose a range in blocks of 5 from horizontal to vertical.  The data was arranged in 7 columns but he wanted the data split into from tabular data to headings on the vertical and the body text going across the columns.  Each block of data was colour coded and this colour scheme was meant to be kept in the output page.  It is an interesting problem and I decided to include a union range so I could include the header row (giving meaning to the data) each time a block of 5 rows was copied and transposed to the new sheet. 

Here is a view of the raw before data.

Here is a view of what we want the data to look like after the procedure runs.

 

The following is the code I settled on.  

Option Explicit

Sub TransposeIt()
   Dim i As Long
   Dim iLen As Integer
   iLen = 5

   With [A1].CurrentRegion
      For i = 2 To [A65536].End(xlUp).Row Step iLen
         Union(.Rows(1), .Rows(i).Resize(iLen)).Copy
         Sheet2.Range("A" & Rows.Count).End(xlUp)(2).PasteSpecial Transpose:=True
      Next
   End With
End Sub

The coding traps the first row, which contains the Excel headings and increments 5 rows each time through the step command. Each loop iterates the rows by 5 so the first iteration will pick up rows 2-6 then rows 7-12 and so on till the bottom of the range is reached. The Union is the intersection between Row1 and the moving rows. The first Union will be rows 1-7 then second will be row 1 and rows 7-12. The following Excel file outlines the procedure and should help to crystallise the procedure.

TransposeIT.xls

Tags Excel, VBA, Transpose, Union, Range, rows
← Excel VBA Number of Printable PagesExcel Maximum Cell Length in a Range →

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.