macro to convert columns into rows

baltusf

New Member
Joined
Jan 24, 2022
Messages
2
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Hi,

I have found a macro that does convert columns into rows, bur when i load the data from a sharepoint-source, than i got a table and than the macro doesn't work.
The macro is :


VBA Code:
Code:

Sub test()


myColumns = 7 'Number of columns to the right of A on sheet1
myRow1 = 2 'First row of data on sheet1
myRow2 = 1 'First row of list on sheet2


Do
    If Range("Sheet1!A" & myRow1).Value = "" Then Exit Do
    For n = 1 To myColumns
        Range("Sheet2!A" & myRow2).Value = Range("Sheet1!A" & myRow1).Value
        Range("Sheet2!B" & myRow2).Value = Range("Sheet1!A1").Offset(0, n).Value
        Range("Sheet2!C" & myRow2).Value = Range("Sheet1!A" & myRow1).Offset(0, n).Value
        myRow2 = myRow2 + 1
    Next n
    myRow1 = myRow1 + 1
Loop


End Sub

I got an error at the first if. I could, convert the table into a list, but then i lost the connection to the original data source.

Is there a solution?

Thanks,
Fred
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.

Forum statistics

Threads
1,215,646
Messages
6,125,997
Members
449,279
Latest member
Faraz5023

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