I need to read sheet1 and produce sheet3 (error in my script)

Please find attached excel with added 3rd sheet . when you click on the Get Data button it will prepare same table as in sheet2 based on the sheet1 . I have a problem if I add more than 163 columns in sheet1. could you help in this? Please find the sheet and the errors attached.

Regards,

Dallag
7-6-2015-8-04-35-AM.png
7-6-2015-8-04-47-AM.png
SimConv-5.3-test.xlsm
Mohammed DallagPetroleum ConsultantAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rory ArchibaldCommented:
You can't use ADO with more than 255 columns, so this approach will not work based on that data set.

Do you actually have any data with multiple rows for the same date?
0
Mohammed DallagPetroleum ConsultantAuthor Commented:
Can you change the script without using ADO. the data are using well and date.

Regards,

Dallag
0
Rory ArchibaldCommented:
Do you actually have any data with multiple rows for the same date?
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Mohammed DallagPetroleum ConsultantAuthor Commented:
Yes
0
Rory ArchibaldCommented:
Try this:

Private Sub CommandButton1_Click()
    Dim lr                    As Long
    Dim col_count             As Long
    Dim x                     As Long
    Dim y                     As Long
    Dim lCounter              As Long
    Dim vSource
    Dim vOut

    Application.ScreenUpdating = False

    lr = Cells(Rows.Count, 1).End(xlUp).Row
    Range("A2:C" & lr).Clear

    vSource = Sheet1.Range("A1").CurrentRegion.Value2

    ReDim vOut(1 To (UBound(vSource, 1) - 1) * (UBound(vSource, 2) - 1) + 1, 1 To 3)
    ' convert well numbers
    For y = LBound(vSource, 2) + 1 To UBound(vSource, 2)
        vSource(1, y) = Left$(vSource(1, y), 4) & "-" & Val(Mid$(Replace$(vSource(1, y), "_", ""), 5, 4))
    Next y

    ' add headers
    vOut(1, 1) = "Well"
    vOut(1, 2) = "Date"
    vOut(1, 3) = "wopr"

    lCounter = 2

    For x = LBound(vSource) + 1 To UBound(vSource)
        For y = LBound(vSource, 2) + 1 To UBound(vSource, 2)
            vOut(lCounter, 1) = vSource(1, y)
            vOut(lCounter, 2) = vSource(x, 1)
            vOut(lCounter, 3) = vSource(x, y)
            lCounter = lCounter + 1
        Next y
    Next x

    Range("A1").Resize(UBound(vOut), UBound(vOut, 2)).Value2 = vOut
    Range("B:B").NumberFormat = "dd-mmm-yy"

    Application.ScreenUpdating = True

End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mohammed DallagPetroleum ConsultantAuthor Commented:
Thank you so much. It is working fine.

Regards,

Dallag
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.