Vba code correction

ANTONIO1981

Board Regular
Joined
Apr 21, 2014
Messages
162
HI I added an extra column into the spreadsheet (column D)

the code was working well without that column.

im not sure how to correct it attached.

New sites renovation table.xlsx - Google Drive

the data should be displayed in columns in sheet 2 (NEW_SITES_RENOVATIONS_TABLE


Code:
Sub NEW_SITES_RENOVATIONS_TABLE()
Dim Ray As Variant, n As Long, Ac As Long, c As Long
Ray = Sheets("NEW_SITES_RENOVATIONS").Range("A1").CurrentRegion.Resize(, 17)
ReDim nray(1 To UBound(Ray, 1) * UBound(Ray, 2) + 1, 1 To 6)
c = 1
 nray(c, 1) = Ray(1, 1)
 nray(c, 2) = Ray(1, 2)
 'nray(c, 3) = Ray(1, 3)
 nray(c, 3) = Ray(1, 3)
 nray(c, 4) = "Date"
 nray(c, 5) = "Amount"


For n = 2 To UBound(Ray, 1)
     For Ac = 5 To UBound(Ray, 2)
        c = c + 1
        nray(c, 1) = Ray(n, 1)
        nray(c, 2) = Ray(n, 2)
        'nray(c, 3) = Format(Ray(n, 3), "mmm_yy")
        nray(c, 3) = Ray(n, 3)
        If IsDate(Ray(1, Ac)) Then
                nray(c, 4) = CDate(Ray(1, Ac))
        Else
                nray(c, 4) = Ray(1, Ac)
        End If
        nray(c, 5) = Format(Ray(n, Ac), "#,##0.00000")
    Next Ac
Next n
Sheets("NEW_SITES_RENOVATIONS_TABLE").Cells.ClearContents
Sheets("NEW_SITES_RENOVATIONS_TABLE").Range("A1").Resize(c, 5) = nray
End Sub
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Good you know how to post a link and what a cross-post is , maybe then you can post a link next you cross-post as per the forum rules on both sites :biggrin:

and no it is unlikely that the post will be deleted by a moderator.

do i need to post again?

Sigh... no then you would be creating a duplicate post. I would recommend reading the forum rules on both sites.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,836
Messages
6,181,248
Members
453,026
Latest member
cknader

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