Search code examples
excelvbapivotpowerqueryunpivot

Unpivot code set returns an error in Resize Ubound function


I'm trying to unpivot an array of data. I was able to do this before from a slightly different Source data, thanks to our good sir's help mr. Tim Williams who answered my previous question on this ( Link to my previous question), however, now i'm using a slightly different source data.

I was pretty sure that I have to only change the number of columns that will be fixed in

p = UnPivotData(ThisWorkbook.Sheets("Projects Data").Range("A1").CurrentRegion, _
    114, True, True)

i.e. 114. But for some reason I get an error in this part

.Range("A1").Resize(UBound(p, 1), UBound(p, 2)).Value = p 

It also does work for some couple of lines and after that the error kicks in. I'm not sure what seem to be the error here. I've been trying to work on this for two days and I'm sleep deprived and frustrated,so as usual, I would really be very happy and appreciate your help on this.

Here's an extract of the file that i'm working on with it's code.


Solution

  • The issue is that in your data appears #1837-10-07 17:31:12#. But Excel cannot display dates before 1900. Therefore it fails to write that data and aborts.

    The problem is the column DI in Projects Data is formatted as Date but there are no dates in it. Fix that number format to General and your function works as expected.