Forum Discussion

SamFares's avatar
SamFares
Brass Contributor
Dec 12, 2020
Solved

VBA Copying data from certain columns one sheet to rows in another sheet

Hello, There are two tabs in my Excel Book.  The data source (data copied from) is (Jedi WN joists) tab to be pasted into the rows in (Span=50', Depth=26"-48"). I indicated in column "O" in (Span=50...
  • Riny_van_Eekelen's avatar
    Dec 13, 2020

    SamFares As mathetes suggested, there is no need for VBA here. In the attached file, I have added an INDEX/MATCH formula to find the Joist Depth in the data table (named it JoistData). But, I needed to clean-up both sheets a little bit.

    As said, I gave the original "Table134" (sheet Jedi ....) a more descriptive name, JoistData, and added a column to the far right extracting the first two characters of the Description column, so that I could match them with the joist depths in "Span" column B. To make this work, I got rid of the merged cells in column B (they cause nothing but trouble) and copied down the depths for each group of four rows. Then, I made sure that the row headers used in column D (Span) are exactly matching those used in JoistData (Jedi).

    The resulting formula in E5 looks like this:

    =INDEX(JoistData,MATCH($B5,'Jedi WN Joists'!$AG:$AG,0)+COLUMN()-COLUMN($E$1)-1,MATCH($D5,JoistData[#Headers],0))

    .... and it was copied down and across.

    Now, there is one weakness in your data. You have two groups, both with a depth of 30. If this is indeed correct, the values for the 2nd group will (or may) be incorrect, using the above formula. I'm referring to items J21 through J40 in the JoistData.

     

    Since you already started noting down the applicable ranges to be copied (column O, Span), you perhaps want to continue on that path. Change texts like "AD2-AD11" to "AD2:AD11" to make it look like a reference to a range, so that you can call it with INDIRECT. The following formula transposes the values for each of the 10 rows in a group (Jedi) to a single row with 10 columns. Its demonstrated in rows 56:59 on the Span-sheet.

    =TRANSPOSE(INDIRECT("'Jedi WN Joists'!"&O56))

     Enter the formula with Ctrl-Shift-Enter if your Excel version doesn't not support dynamic array functions.

Resources