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 change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney

Forum statistics

Threads
1,214,593
Messages
6,120,434
Members
448,961
Latest member
nzskater

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