+ Reply to Thread
Results 1 to 6 of 6

Macro for transposing values

  1. #1
    Registered User
    Join Date
    05-28-2017
    Location
    Buckingham, England
    MS-Off Ver
    2013
    Posts
    10

    Macro for transposing values

    Hi - I'm new here, and to writing macros, and would really appreciate some help. I'm looking to transpose a set of values as set out below...and just can't make it work.

    Query.jpg

    Any help would be greatly appreciated.
    Attached Images Attached Images

  2. #2
    Registered User
    Join Date
    05-28-2017
    Location
    Buckingham, England
    MS-Off Ver
    2013
    Posts
    10

    Re: Macro for transposing values

    Apologies, ignore the second image. Ideally, I would like to transpose the values to a new worksheet in the same workbook. Thanks in advance!

  3. #3
    Registered User
    Join Date
    06-05-2013
    Location
    USA
    MS-Off Ver
    2003, 2010, 2013, 2016
    Posts
    12

    Re: Macro for transposing values

    This isn't quite the normal transpose, so unless someone else has a better idea, I would use loops to go through the first range and then make the second table. There are faster ways to do this with arrays, but below is one way. Please adapt as needed.

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    05-28-2017
    Location
    Buckingham, England
    MS-Off Ver
    2013
    Posts
    10

    Re: Macro for transposing values

    bkm2016....you're a hero. Brilliant - I'll tweak this accordingly. Thanks so much.

  5. #5
    Forum Expert
    Join Date
    08-16-2015
    Location
    Antwerpen, Belgium
    MS-Off Ver
    2007-2016
    Posts
    2,380

    Re: Macro for transposing values

    If data start in A1
    and no emty Cells in first Row or first Column
    this can do




    Kind regards
    Leo
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    05-28-2017
    Location
    Buckingham, England
    MS-Off Ver
    2013
    Posts
    10

    Re: Macro for transposing values

    Apologies for reopening the thread, however my requirements have changed slightly (set out below). I now need to transpose three cells of data and excluding the 'period' header in the example above. Examples set out below:

    From this:

    Transposed.PNG

    To this:

    Book 1 [51863].PNG


    Here's the current code:

    Sub Data_transpose()
    Dim StartRange As Range
    Set StartRange = Sheet1.UsedRange
    Sheets.Add.Name = "Transposed"
    ActiveCell.FormulaR1C1 = "Member Name"
    ActiveCell.Interior.ColorIndex = 48
    Range("B1").Select
    ActiveCell.FormulaR1C1 = "Period"
    ActiveCell.Interior.ColorIndex = 48
    Range("C1").Select
    ActiveCell.FormulaR1C1 = "Amount"
    ActiveCell.Interior.ColorIndex = 48
    Dim NewStart As Range
    Set NewStart = Range("A2")
    Dim j As Long

    For r = 2 To StartRange.Rows.Count
    For i = 2 To StartRange.Columns.Count
    If StartRange.Cells(r, i).Value > 0 Then
    NewStart.Offset(j).Value = StartRange.Cells(r, 1).Value
    NewStart.Offset(j, 1).Value = StartRange.Cells(1, i).Value
    NewStart.Offset(j, 2).Value = StartRange.Cells(r, i).Value
    j = j + 1
    End If
    Last edited by TimC1974; 05-30-2017 at 03:19 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Copying / transposing values in another sheet
    By grkchakri in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-28-2015, 08:53 AM
  2. Replies: 9
    Last Post: 02-24-2015, 06:51 AM
  3. Sorting and transposing values in non-adjacent cells
    By Rablet in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 04-24-2014, 06:14 AM
  4. Transposing list of values with 6 zeroes in front to retain the zero after transposing
    By Lisa4legin in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-16-2013, 03:34 AM
  5. Transposing Date Values
    By Boendog in forum Excel General
    Replies: 6
    Last Post: 07-09-2012, 09:14 AM
  6. Keep last row format/values when transposing values from one worksheet to another
    By BuzzOffSweetheart in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-18-2012, 02:27 PM
  7. transposing values top to bottom
    By Ted Metro in forum Excel General
    Replies: 3
    Last Post: 04-18-2005, 11:06 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1