[SOLVED] Stack columns from a matrix


"Excel VBA Help"

 


Play Friv Now - Play Friv Games
Go Back   The Code Cage Forums > Microsoft Topics > Microsoft Excel Forum
Our Info Pages:-
The Code Cage - Microsoft Office help

Notices

Microsoft Excel Forum Members Post questions in this forum if they are related to using Microsoft Excel, this includes Worksheet Functions, Excel VBA Programming, Simple Macro Code & Charting, Excel formula etc.

New Reply
 
Thread Tools Rating: Thread Rating: 2 votes, 5.00 average. Display Modes
  #1  
Old 22nd January 2010, 02:43
Tom's Avatar
Tom
Newsgroup Contributor
 
Posts: n/a
Posts Per Day: 0
My Top Tip Count:
Default Stack columns from a matrix
     Excel: VBA   


------ Register to get rid of these "In Post" ads! ------

Category: Excel: VBA   

I need a macro to take a 6 column, 6 row matrix, for instance, and stack the
columns 2 at a time on top of each other on another sheet in the spreadsheet.
If the columns were A-F, they would end up stacked
AB
CD
EF

Actually the matrix is about 52 columns by 419 rows with many blanks.

Thanks in advance for the help.
--
Tom

The Code Cage Advertisment
Advertisement
  #2  
Old 22nd January 2010, 05:09
joel's Avatar
joel joel is offline
Expert Member
MS Office Version: MS Office 97
MS Office Skill Level: New to MS Office
 
Join Date: Apr 2009
Age: 61
Posts: 1,252
Posts Per Day: 0.40
My Top Tip Count: 0
Thanks to others: 0
Thanked 6 Times in 6 Posts
Reputation: 220 (23) joel has a spectacular aura aboutjoel has a spectacular aura aboutjoel has a spectacular aura about
Default Re: Stack columns from a matrix

------ Register to get rid of these "In Post" ads! ------


I used PasteSpecial to skip the blanks. sometimes it doesn't work like you would expect if you are copying multiple columns. try this macro first and see if you get good results. change the 10 below to the number of columns you are using. If your last column of data is in Row 1 you can get the last column adding this to the code

LastCol = .cells(1,columns.Count).end(xltoleft).column

Then replace the 10 with LastCol



Sub Copycolumns()


With Sheets("Sheet1")
For ColCount = 1 To 10 Step 2
LastRow = .Cells(Rows.Count, ColCount).End(xlUp).Row
Set CopyRange = .Range(.Cells(1, LastRow), _
.Cells(LastRow, ColCount + 1))
CopyRange.Copy

With Sheets("sheet2")
LastRow = .Cells(Rows.Count, "A").End(xlUp).Row
NewRow = LastRow + 1
.Range("A" & NewRow).PasteSpecial _
Paste:=xlPasteValues, _
SkipBlanks:=True
End With
Next ColCount
End With


End Sub

  #3  
Old 28th June 2011, 07:10
enstmagoo's Avatar
enstmagoo enstmagoo is offline
Junior Member
MS Office Version: MS Office 97, 2003, 2007,2010
MS Office Skill Level: Can use Formulae
 
Join Date: Jun 2011
Location: Provo, United States
Posts: 1
Posts Per Day: 0.00
My Top Tip Count: 0
Thanks to others: 0
Thanked 0 Times in 0 Posts
Reputation: 10 (0) enstmagoo is on a distinguished road
USA
Default Re: Stack columns from a matrix

------ Register to get rid of these "In Post" ads! ------


I have attempted to use this macro with an example I made, a simple 6x6 matrix. When I run the macro, it appears to perform actions, but it results in a matrix that looks the same as the original (with the last column copied).

Any help? How could I get the columns to stack on top of each other, 2 adjacent columns at a time. Much thanks in advance.

The Code Cage Advertisment
Advertisement

To stop seeing these ads and get other benefits check This page!

  #4  
Old 28th June 2011, 09:34
Pete_UK's Avatar
Pete_UK Pete_UK is offline
Solution Centre Professional
MS Office Version: MS Office 2003, 2007
MS Office Skill Level: Proficient with Excel
 
Join Date: Mar 2009
Location: Warrington, England
Age: 65
Posts: 640
Posts Per Day: 0.20
My Top Tip Count: 0
Thanks to others: 8
Thanked 135 Times in 134 Posts
Reputation: 2624 (41) Pete_UK has a reputation beyond reputePete_UK has a reputation beyond reputePete_UK has a reputation beyond reputePete_UK has a reputation beyond reputePete_UK has a reputation beyond reputePete_UK has a reputation beyond reputePete_UK has a reputation beyond reputePete_UK has a reputation beyond reputePete_UK has a reputation beyond reputePete_UK has a reputation beyond reputePete_UK has a reputation beyond repute
Great_Britain
Default Re: Stack columns from a matrix

------ Register to get rid of these "In Post" ads! ------


It's an old thread, so I doubt if Joel will respond to you.

Here is a formula solution (attached). With a 6x6 table set up in A1:F6 of Sheet1, this formula is in A1 of Sheet2:

My Formula:
=INDEX(Sheet1!$A:$F,MOD(ROW(A1)-1,6)+1,2*INT((ROW(A1)-1)/6)+1)


and this one in B1:

My Formula:
=INDEX(Sheet1!$A:$F,MOD(ROW(B1)-1,6)+1,2*INT((ROW(B1)-1)/6)+2)


The only difference is the number at the end of the formula. These two formulae are then copied down to row 18 (beyond which you get the #REF error).

Hope this helps.

Pete
Attached Files To view attachments in this forum your post count must be 2 or greater. You currently have 0 posts.

The Code Cage Advertisment
Advertisement
New Reply
The Code Cage at Facebookhe Code Cage at Twitter


Tags
columns, matrix, stack

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

The Code Cage Affilliates



http://www.thecodecage.com/forumz tested by McAfee Security http://www.thecodecage.com/forumz tested by McAfee Security

All times are GMT +1. The time now is 15:59.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Template-Modifications by TMS
No part of this board, functionality or creatives may be copied or reproduced either in part or full without the express permission of The Code Cage Team.
Copyright ©2008 - , Simon lloyd.
We are not associated with nor employed by Microsoft in any way, we simply provide resources!
All MS office icons are registered trademarks of the application they represent and are used with permission from Microsoft
UA-8135493-1
Cultural Forum | Study at Malaysian University
X vBulletin 3.8.7 Debug Information
  • Page Generation 0.17709 seconds
  • Memory Usage 6,408KB
  • Queries Executed 20 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footerEnd
  • (1)ad_footerStart
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_headerEnd
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_leftcolumn_code
  • (1)ad_navbar_below
  • (3)ad_postbit_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (4)helpful_answers
  • (1)helpfulanswers_javascript
  • (1)navbar
  • (3)navbar_link
  • (2)navbar_noticebit
  • (41)option
  • (4)post_thanks_box
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (4)post_thanks_postbit_info
  • (4)postbit
  • (1)postbit_attachment
  • (4)postbit_ctoptip
  • (3)postbit_onlinestatus
  • (15)postbit_reputation
  • (4)postbit_wrapper
  • (1)showthread_changepostsowner_link
  • (1)showthread_extra_fields
  • (1)showthread_quickreply_mrgdp
  • (1)showthread_reason_popup
  • (1)spacer_close
  • (1)spacer_open
  • (1)su_form
  • (3)tagbit
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_datastore.php
  • ./includes/class_hook.php
  • ./awcoding/plugins/awc.php
  • ./awcoding/plugins/ds.php
  • ./awcoding/plugins/ss.php
  • ./includes/functions_notice.php
  • ./mobiquo/smartbanner.php
  • ./mobiquo/include/classTTConnection.php
  • ./mobiquo/smartbanner/head.inc.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/vbatags.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php
  • ./includes/functions_misc.php
  • ./includes/functions_prefix.php 

Hooks Called:
  • init_startup
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_check_criteria
  • notices_noticebit
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • helpfulanswers_showthreadorpost
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • helpfulanswers_show_normal
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • error_fetch
  • reputation_power
  • reputation_image
  • postbit_imicons
  • postbit_attachment
  • tag_fetchbit
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete