+ Reply to Thread
Results 1 to 18 of 18

macro to change columns (loop)

  1. #1
    Registered User
    Join Date
    07-09-2013
    Location
    Poland
    MS-Off Ver
    excel 2007
    Posts
    85

    macro to change columns (loop)

    Hi
    i have a problem. product is specified by the number and my file contains data day by day. What i want my macro to do is to change data in the columns to be one by one in the rows just like in example showed in my file. I have like no idea how to start i am new to vba.

    thx for all your help
    Attached Files Attached Files
    Last edited by mumsys; 07-12-2013 at 08:20 AM.

  2. #2
    Forum Expert
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    2,387

    Re: macro to change columns (loop)

    mumsys,

    Thanks for the workbook.

    With your raw data in worksheet Sheet1. A new worksheet Results will be created to hold the results you are looking for.

    Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

    1. Copy the below code, by highlighting the code and pressing the keys CTRL + C
    2. Open your workbook
    3. Press the keys ALT + F11 to open the Visual Basic Editor
    4. Press the keys ALT + I to activate the Insert menu
    5. Press M to insert a Standard Module
    6. Where the cursor is flashing, paste the code by pressing the keys CTRL + V
    7. Press the keys ALT + Q to exit the Editor, and return to Excel
    8. To run the macro from Excel, open the workbook, and press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.

    Please Login or Register  to view this content.
    Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm

    Then run the ReorgData macro.
    Have a great day,
    Stan

    Windows 10, Excel 2007, on a PC.

    If you are satisfied with the solution(s) provided, please mark your thread as Solved by clicking EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

  3. #3
    Forum Expert
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    2,387

    Re: macro to change columns (loop)

    mumsys,

    I have like no idea how to start i am new to vba.
    See if something below will assist you:


    Training / Books / Sites as of 6/26/2013

    What Is VBA?
    VBA is an acronym for Visual Basic for Applications. VBA should not be confused with VB, which is standard Visual Basic. Visual Basic for Applications is a programming feature designed by Microsoft for use with their Microsoft Office

    MrExcel's Products: Books, CDs, Podcasts Discuss topics related to Holy Macro! Products: Learn Excel from MrExcel, VBA and Macros for Microsoft Excel,Holy Macro! It's 2500 VBA Examples CD, Guerilla Data Analysis Using Microsoft Excel and Excel Knowledge Base CD and the MrExcel Podcasts.
    http://www.mrexcel.com/forum/forumdisplay.php?f=19

    There are over 1800 Excel videos/tutorials here:
    http://www.youtube.com/user/ExcelIsFun

    Getting Started with VBA.
    http://www.datapigtechnologies.com/ExcelMain.htm

    If you are serious about learning VBA try
    http://www.add-ins.com/vbhelp.htm

    Excel Tutorials and Tips - VBA - macros - training
    http://www.mrexcel.com/articles.shtml

    Microsoft Office training
    http://office.microsoft.com/en-us/tr...101782702.aspx

    Free VBA Course
    http://www.excel-pratique.com/en/vba.php

    Excel 2007 VBA materials to learn here:
    http://www.worldbestlearningcenter.c...erstanding.htm

    Here's a good primer on the scope of variables.
    http://www.cpearson.com/excel/scope.aspx

    Using Variables in Excel VBA Macro Code
    http://www.ozgrid.com/VBA/variables.htm

    See David McRitchie's site if you just started with VBA
    http://www.mvps.org/dmcritchie/excel/getstarted.htm

    What is a Visual Basic Module?
    http://www.emagenit.com/VBA%20Folder...vba_module.htm

    Here is a good introductory tutorial using a VBA Class:
    http://www.cpearson.com/excel/classes.aspx

    Ron de Bruin's intro to macros:
    http://www.rondebruin.nl/code.htm

    Ron's Excel Tips
    http://www.rondebruin.nl/tips.htm

    Ron de Bruin's Mail from Excel and make/mail PDF files (Windows)
    http://www.rondebruin.nl/win/section1.htm

    Anthony's Excel VBA Page - Excel Application - Excel Consultant - Excel Consulting (see 3 tutorials in Excel VBA Basic Tutorial Series)

    http://www.jlathamsite.com/Teach/VBA...troduction.pdf (95 page "book")

    BET: Microsoft Excel Visual Basic

    Creating An XLA Add-In For Excel, Writing User Defined Functions In VBA
    http://www.cpearson.com/excel/createaddin.aspx

    How do I create a PERSONAL.XLS(B) or Add-in
    http://www.rondebruin.nl/personal.htm

    Creating custom functions
    http://office.microsoft.com/en-us/ex...117011033.aspx

    Writing Your First VBA Function in Excel
    http://www.exceltip.com/st/Writing_Y...Excel/631.html

    VBA for Excel (Macros)
    http://www.excel-vba.com/excel-vba-contents.htm

    Excel Macros Tutorial
    http://www.excel-vba.com/excel-vba-contents.htm

    Excel Macros & Programming
    http://www.excel-vba.com/index.htm

    VBA Lesson 11: VBA Code General Tips and General Vocabulary
    http://www.excel-vba.com/vba-code-2-1-tips.htm

    Excel VBA -- Adding Code to a Workbook
    http://www.contextures.com/xlvba01.html

    Beyond Excel's recorder

    Helpful as a simple concise reference for the basics, and, using the macro recorder is endlessly powerful.
    http://www.techonthenet.com/excel/cells/index.php

    Learn to debug:
    http://www.cpearson.com/excel/debug.htm

    How To: Assign a Macro to a Button or Shape
    http://peltiertech.com/WordPress/how...tton-or-shape/

    User Form Creation
    http://www.contextures.com/xlUserForm01.html

    When To Use a UserForm & What to Use a UserForm For
    http://www.ozgrid.com/Excel/free-tra...ba2lesson2.htm

    Excel Tutorials / Video Tutorials - Functions
    http://www.contextures.com/xlFunctions02.html

    How to insert Buttons, radio buttons and check boxes in Excel
    http://www.bing.com/videos/search?q=...xcel&FORM=VDRE

    INDEX MATCH - Excel Index Function and Excel Match Function
    http://www.contextures.com/xlFunctions03.html

    Excel Data Validation
    http://www.contextures.com/xlDataVal08.html#Larger
    http://www.contextures.com/excel-dat...ation-add.html

    Excel -- Data Validation -- Create Dependent Lists
    http://www.contextures.com/xlDataVal02.html

    Your Quick Reference to Microsoft Excel Solutions
    http://www.xl-central.com/index.html

    New! Excel Recorded Webinars
    http://www.datapigtechnologies.com/ExcelMain.htm

    Fuzzy Matching - new version plus explanation

    Programming The VBA Editor - Created by Chip Pearson at Pearson Software Consulting LLC
    This page describes how to write code that modifies or reads other VBA code.
    http://www.cpearson.com/Excel/vbe.aspx

    VBA and Macros for Microsoft Excel, by Bill Jelen "Mr.Excel" and Tracy Syrstad

    Excel Hacks 100 Industrial-Strength Tips & Tools, by David & Traina Hawley

    VBA and Macros for Microsoft Excel 2007, by Bill Jelen "Mr.Excel" and Tracy Syrstad

    Excel 2007 Book: you can try this...there is a try before you buy ebook available at this link…

    by Stephen/ Bovey, Rob/ Green, John Bullen (Paperback - Feb 11, 2005)
    Professional Excel Development

    by Rob Bovey, Stephen Bullen, John Green, and Robert Rosenberg (Paperback - Sep 26, 2001)
    Excel 2002 VBA: Programmers Reference

    "Professional Excel Development" by Rob Bovey, Dennis Wallentin, Stephen Bullen, & John Green

    DonkeyOte: My Recommended Reading, Volatility
    http://www.decisionmodels.com/calcsecretsi.htm

    Sumproduct
    http://www.xldynamic.com/source/xld.SUMPRODUCT.html

    Arrays
    http://www.mrexcel.com/forum/showthread.php?t=390246
    http://www.cpearson.com/excel/VBAArrays.htm
    http://www.xtremevbtalk.com/showthread.php?t=296012
    http://www.vbtutor.net/vba/vba_chp21.htm

    Array Dimensions in Visual Basic - Working with Dimensions (code and graphics)
    http://msdn.microsoft.com/en-us/libr...(v=VS.80).aspx

    Shortcut Keys in Excel 2000 through 2007

    Pivot Intro
    http://peltiertech.com/Excel/Pivots/pivotstart.htm
    Office 2010 Class #36: Excel PivotTables Pivot Tables 15 examples (Data Analysis) - YouTube
    http://www.youtube.com/watch?v=qMGILHiLqr0
    Getting Started with Pivot Tables
    http://www.contextures.com/xlPivot01.html#Start
    Overview of PivotTable and PivotChart reports
    http://office.microsoft.com/en-gb/ex...010342752.aspx
    Build a Pivot Table in Excel VBA
    http://www.brainbell.com/tutorials/E...Excel_VBA.html

    Email from XL - VBA
    http://www.rondebruin.nl/sendmail.htm

    Outlook VBA
    http://www.outlookcode.com/article.aspx?ID=40

    Function Dictionary
    http://www.xlfdic.com/

    Function Translations
    http://www.piuha.fi/excel-function-name-translation/

    Dynamic Named Ranges
    http://www.contextures.com/xlNames01.html

    How to create Excel Dashboards
    http://www.mrexcel.com/Excel-dashboards-Xcelsius.html
    http://www.contextures.com/excel-dashboards.html
    http://chandoo.org/wp/excel-dashboards/
    http://chandoo.org/wp/management-dashboards-excel/
    http://www.exceldashboardwidgets.com/
    http://www.andypope.info/charts/gauge.htm

    Excel Dashboard / Scorecard Ebook
    http://www.qimacros.com/excel-dashboard-scorecard.html

    Mike Alexander from Data Pig Technologies
    http://www.amazon.com/Excel-2007-Das...5564958&sr=1-1

    Templates
    http://www.cpearson.com/Excel/Topic.aspx
    http://www.contextures.com/excel-tem...lf-scores.html
    http://www.ozgrid.com/search/templates.htm

    Microsoft Excel Cascading Listboxes Tutorial
    http://www.youtube.com/watch?v=YAMvLJRwZdI

    Date & Time stamping:
    http://www.mcgimpsey.com/excel/timestamp.html

    Get Formula / Formats thru custom functions:
    http://dmcritchie.mvps.org/excel/formula.htm#GetFormat

    A nice informative MS article "Improving Performance in Excel 2007"
    http://msdn.microsoft.com/en-us/library/aa730921.aspx

    Progress Meters
    http://www.andypope.info/vba/pmeter.htm
    http://www.xcelfiles.com/ProgressBar.html

    How to convert text to numbers in Excel
    http://support.microsoft.com/kb/291047

    How to parse data from the web - Brett Fret has a video in YouTube
    http://www.youtube.com/watch?v=6H7tBL97orE

    And, as your skills increase, try answering posts on sites like:
    http://www.mrexcel.com
    http://www.excelforum.com
    http://www.ozgrid.com
    http://www.vbaexpress.com
    http://www.excelfox.com

    If you are willing to spend money for the training, then something here should work for you...
    Amazon.com: excel tutorial dvd
    http://www.amazon.com/s/?ie=UTF8&key...l_5givffg47i_b

    Advanced Excel Training - Online Excel Course
    http://www.udemy.com/advanced-excel/

  4. #4
    Registered User
    Join Date
    07-09-2013
    Location
    Poland
    MS-Off Ver
    excel 2007
    Posts
    85

    Re: macro to change columns (loop)

    This is just perfect. Thank You so much

  5. #5
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: macro to change columns (loop)

    The code should work as long as you have consistent data. The output is in new sheet
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    07-09-2013
    Location
    Poland
    MS-Off Ver
    excel 2007
    Posts
    85

    Re: macro to change columns (loop)

    Hi its me again i have only one question to this macro. Please see the attachment for my problem.
    The point is that if I put a few more of columns (i changed the code to make it possible) macro hits me up with the row transposed as a column right before my values that i wanted to have ;( Please run the macro for yourself and you will be able to understand thx in adadvance
    Attached Files Attached Files

  7. #7
    Forum Expert
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    2,387

    Re: macro to change columns (loop)

    mumsys,

    Thanks for your latest workbook.

    Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

    Please Login or Register  to view this content.
    Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm

    Then run the ReorgDataV2 macro.

  8. #8
    Registered User
    Join Date
    07-09-2013
    Location
    Poland
    MS-Off Ver
    excel 2007
    Posts
    85

    Re: macro to change columns (loop)

    Quote Originally Posted by stanleydgromjr View Post
    mumsys,

    Thanks for your latest workbook.

    Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).


    Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm

    Then run the ReorgDataV2 macro.
    Hi, thanks for your help. really appreciated it
    i don't know if it run wrong for you, but I have data only from day 2 what about day 1?

    And second question what if my data would start I dont know - at Cell (26,1) for example? How should I change the code?

  9. #9
    Forum Expert
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    2,387

    Re: macro to change columns (loop)

    mumsys,

    Please do not quote entire replies from your helper. When quoting follow these guidelines:
    1. Quote ONLY if it is needed to add clarity or context for your reply. If so, then
    2. Quote ONLY the specific part of the post that is relevant - - not the entire post.
    This will keep thread clutter to a minimum and make the discussion easier to follow.


    I found the error - it's working correctly now.


    Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

    Please Login or Register  to view this content.
    Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm

    Then run the ReorgDataV3 macro.

  10. #10
    Forum Expert
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    2,387

    Re: macro to change columns (loop)

    mumsys,

    And second question what if my data would start I dont know - at Cell (26,1) for example? How should I change the code?
    Please attach the new/updated workbook.

  11. #11
    Registered User
    Join Date
    07-09-2013
    Location
    Poland
    MS-Off Ver
    excel 2007
    Posts
    85

    Re: macro to change columns (loop)

    Stanleydgromj,

    thanks for the help so far now i see a subscript out of range problem when i put more data

    I attached the workbook , PRODUCT TYPE NUMBER (and all words in capital letters are names of categories and they are not important, only days are )
    I want the same thing to happen, next sheet with results,

    Thx in advance
    Attached Files Attached Files

  12. #12
    Forum Expert
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    2,387

    Re: macro to change columns (loop)

    mumsys,

    We have now seen three different worksheet configurations.

    The first two did not have titles in the same row where you had day1, day2, ....

    This latest workbook has titles to the left of, and, in the same row as day1, day2,...?????


    In order to continue I will have to see the actual raw data that you are working with - then I can create a macro that can be adjustable for product, type, nr's, and days.


    If you can not supply the actual raw data that you are working with, then:

    In the Quick Reply box, just put the word BUMP. Then, click on the Post Quick Reply button, and someone else will assist you.
    Last edited by stanleydgromjr; 07-16-2013 at 02:21 PM.

  13. #13
    Registered User
    Join Date
    07-09-2013
    Location
    Poland
    MS-Off Ver
    excel 2007
    Posts
    85

    Re: macro to change columns (loop)

    Hi,
    Yes they have titles on the left, the actual raw data looks exactly like I attached, only the products have names instead of product1 etc. its a data export that looks just like I send Is that a problem that there are this titles?

    I could send actual data but now i just changed the names of products to "product1"

    Best regards

  14. #14
    Forum Expert
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    2,387

    Re: macro to change columns (loop)

    mumsys,

    One last try.

    In order to continue I will have to see the actual raw data that you are working with - then I can create a macro that can be adjustable for product, type, nr's, and days.

    If you can not supply the actual raw data that you are working with, then:

    In the Quick Reply box, just put the word BUMP. Then, click on the Post Quick Reply button, and someone else will assist you.

  15. #15
    Registered User
    Join Date
    07-09-2013
    Location
    Poland
    MS-Off Ver
    excel 2007
    Posts
    85

    Re: macro to change columns (loop)

    Stanleydgromjr,

    Hope it helps thank you

    The data is generated every week, it can have more or less rows.
    Attached Files Attached Files

  16. #16
    Forum Expert
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    2,387

    Re: macro to change columns (loop)

    mumsys,

    Thanks for the latest workbook you posted.

    This final macro searches worksheet Sheet1, between column 1 thru column 10, for title product number.

    Then it searches for the row in the found column for product number, and the column in that same row for Day1, and the last used column in that same row.

    Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

    Please Login or Register  to view this content.
    Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm

    Then run the ReorgDataV4 macro.
    Last edited by stanleydgromjr; 07-17-2013 at 02:47 PM.

  17. #17
    Registered User
    Join Date
    07-09-2013
    Location
    Poland
    MS-Off Ver
    excel 2007
    Posts
    85

    Re: macro to change columns (loop)

    Stan,
    Thank you sooo much Sorry for inconveniences. It works perfectly!

  18. #18
    Forum Expert
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    2,387

    Re: macro to change columns (loop)

    mumsys,

    You are very welcome. Glad I could help.

    Thanks for the feedback.

    And, come back anytime.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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