Automatically creating 8x12 grids on one workbook from 96 row list on another workbook

  • Hello,


    I am very new to macros and VBA but trying to improve. Each time I conduct an experiment a raw database is automatically generated. In the raw database each data set is arranged in 1 column with 96 rows (there are multiple columns of 96 on each raw data base). I need to transfer this data to another workbook which is my Final data base and on the final database I would like the data to be formatted in 8x12 grids (one for each column of 96). The way this is currently being done is very slow and error prone so I am trying to automate it.


    For each RAW data workbook that is generated I would like to use a template of the final data workbook so that I can create 1 final data workbook which includes 8x12 grids for each column of 96 on the raw data sheet.


    I initially used this formula "INDEX(A1:A96, TRANSPOSE(SEQUENCE(12,8)))" using excel 365 and that worked, but realised that the PC that I need to use the databases on has Excel 2019 which does not have the SEQUENCE function.


    I am very new to macros and VBA but I was hoping someone could help me write a VBA code to create a function or a command button to do what I would like to do. (Hope it all makes sense - see attachments also)


    Thank you in advance

  • Hello,


    Just realized you made it clear you had a preference for a macro ...


    Attached is a demo file in order to transform a List into a Matrix ...


    It will require to be adapted to your specific situation, and to the exact structure of your workbooks ...

    To help you out, comments (-shown in green within the code-) should assist you for all your modifications ... ;)


    Hope this will help

  • maehar


    Once you have tested both proposals :


    1. the first one with a Function ...

    and

    2. the second one with a Macro ...


    Feel free to share your comments ...

    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Smiley" icon, below, in the bottom right corner :)

  • What would explain the total lack of reactions ... ???

    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Smiley" icon, below, in the bottom right corner :)

  • Hi,


    Apologies for the late reply, I have been very busy at work and I have not had time to look in detail at the options and try them out. Thank you for these options.


    As soon as I have had a try I will leave my comments.

  • Hi,


    Apologies for the late reply, I have been very busy at work and I have not had time to look in detail at the options and try them out. Thank you for these options.


    As soon as I have had a try I will leave my comments.

    Thanks for your reaction ...

    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Smiley" icon, below, in the bottom right corner :)

  • Hi,


    Apologies again for the late reply. I have had a look and the Matrix works perfectly, Thank you very much!

    Do you know how/if I can still do this if my RAW data (list of 96) is in a different workbook to the final data (the 8x12 grid) that I want to output using the matrix (do I change the name of the location of the destination workbook?)


    And how would I turn this into a workbook that I can use every time (as a template) to transform my data? After every experiment, the raw data is automatically generated from the software I use for the experiment and I generate the final data workbook myself. But I would like to have a template so that I can quickly transform it every time.

  • Glad to hear this could help you out


    Your question about two separate workbooks would simply require following modification:

    Code
    Dim wkbdest As Workbook, wkbsour As Workbook
    ' Then you obviously need to Set the two new variables and change the instruction to 
    wkbdest.Sheet1.Cells(i + ldRow - 1, j + ldCol - 1).Value = wkbsourc.Sheet1.Cells(lsrow, lscol).Value

    Hope this will help

    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Smiley" icon, below, in the bottom right corner :)

  • Hi,


    Thank you. I have tried to make this modification. Ill attach a screen shot of the change I made. However, I get an error code "Subscript out of range".


    I have probably done this wrong, could you please clarify?


    Code:


  • Hi again,


    When it is coming to your workbooks, you do need to think over the fact that

    1. Both of them are already opened whenever you run your macro

    or

    2. Your source workbook contains an instruction, within your macro, to open the relevant workbook


    Hope this clarifies

    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Smiley" icon, below, in the bottom right corner :)

  • Hi,


    Have you been able to fix this very last problem ...?

    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Smiley" icon, below, in the bottom right corner :)

  • Hi,


    Unfortunately not, I have the source and destination workbooks open when I try and run the command button, but I am getting this error code "Object doesn't support this property and method" so I think I am naming the file in the wrong way.



    Also, similarly to the second part of my previous question. As a new raw data file is generated every time will I have to go into the VBA every time and change the file source and destination or is there a way I can automate this with a basic template workbook?


    Thank you for your continued help. Much appreciated!

  • Hi again,


    When copying a Range between opened workbooks using the Cells() method, you have to be cautious, since you must define both the workbook as well as the worksheet ... ;)


    see example below :



    Hope this clarifies (and will help...) :)

    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Smiley" icon, below, in the bottom right corner :)

  • Hi,

    Could you please show me how to integrate that into the original code?


    Thank you

  • Hello,


    Since you are very new to macros and VBA ... should you need some more assistance ...


    Do not hesitate to post your VBA code i.e. the whole of your macro ( BUT PLEASE NOT an IMAGE !!! )

    so that all necessary modifications can be easily made ... ;)


    Cheers


    P.S. Use the Code Tags shown "</>" in the menu ...

    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Smiley" icon, below, in the bottom right corner :)

  • Hi again,


    Below is the macro to be adjusted to your actual situation ... and to be tested :

    Hope this will help

    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Smiley" icon, below, in the bottom right corner :)

  • After testing the macro, thanks for your feedback

    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Smiley" icon, below, in the bottom right corner :)

  • Hello,


    I have tested the macro and adjusted it to my situation but I am getting an error (on the part in red). The error is - Method 'Range' of object'_Worksheet' failed.


    Thank you

  • Replace this:

    Code
    With wkbsour
    .Range(.Cells(lsrow, lscol)).Copy wkbdest.Cells(i + ldRow - 1, j + ldCol - 1)
    End With


    with this:


    Code
    wkbsour.Cells(lsrow, lscol).Copy wkbdest.Cells(i + ldRow - 1, j + ldCol - 1)


    I'd also suggest renaming the variable since it isn't a workbook object.

    Rory
    Theory is when you know something, but it doesn’t work. Practice is when something works, but you don’t know why. Programmers combine theory and practice: nothing works and they don’t know why

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!