Create a new table starting from another one

anpak

New Member
Joined
Oct 19, 2021
Messages
15
Office Version
  1. 365
Platform
  1. Windows
Hello,

I'm new on this forum. Below my first question :)

I would like to create a macro in order to obtain the table named "Output" starting from the table named "Input". Please see the image below.

Is it possible?

1634652188479.png



Thank you in advance :)
 
Fluff thank you it works!!!

Please can you add those "features":
  1. If the cell in Input table is blank, the vba script have not to create the row in the output table (as in the image, Role 1 Tool 4)
  2. The output table must have the header: Role (A1) and Tool (A2).
Thank you in advance
 
Upvote 0

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
This will add the header
VBA Code:
Sub anpak()
   Dim Ary As Variant, Nary As Variant
   Dim r As Long, c As Long, nr As Long
   
   With Sheets("Sheet1")
      c = .Cells(1, Columns.Count).End(xlToLeft).Column
      Ary = .Range("A2", .Range("A" & Rows.Count).End(xlUp)).Resize(, c).Value2
   End With
   ReDim Nary(1 To UBound(Ary) * c, 1 To 2)
   
   For r = 1 To UBound(Ary)
      For c = 2 To UBound(Ary, 2)
         If Ary(r, c) <> "" Then
            nr = nr + 1
            Nary(nr, 1) = Ary(r, 1)
            Nary(nr, 2) = Ary(r, c)
         End If
      Next c
   Next r
   With Sheets("Sheet2")
      .Range("A1:B1").Value = Array("Role", "Tool")
      .Range("A2").Resize(nr, 2).Value = Nary
   End With
End Sub
Part 1 is already done.
If you are getting "blank"cells in the output then your input cells are not empty.
 
Upvote 0
Solution
Ok Fluff, now the vba script is perfect.

Thank you so much for your support!!!
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0
Sorry Fluff, one more feature.

Is it possible to start writing the output table not always from "A2", but starting from the first blank cell in column A?
 
Upvote 0
Yup, you can do that like
VBA Code:
      .Range("A" & Rows.Count).End(xlUp).Offset(1).Resize(nr, 2).Value = Nary
 
Upvote 0
Glad to help & thanks for the feedback.
 
Upvote 0
Hello @Fluff ,

I would like a script that just transposes the first line in a sheet (excluded the first two cells-A1,A2) in the first column of another sheet, after last blank cell.

Could you help me please?

Regards,
Antonio
 
Upvote 0
As that's a totally different question, it needs a new thread. Thanks
 
Upvote 0

Forum statistics

Threads
1,215,066
Messages
6,122,948
Members
449,095
Latest member
nmaske

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top