Runtime Error 6 - Overflow error with a variant type variable [Closed]

Dear All,

Kindly help me with the below coding where i get Runtime Error 6 - Overflow error when executed.

Private Sub Workbook_Open()
Dim ws As Worksheet
Dim rngspace As Range
Dim lRows As Long, lCols As Long
Dim arrdata() As Variant
Dim arrReturnData() As Variant
Dim p As Long, q As Long

'Trimming whitspaces

Set ws = Worksheets("Sheet1")
Set rngspace = ws.Range("A1").CurrentRegion

lRows = rngspace.Rows.Count
lCols = rngspace.Columns.Count

ReDim arrdata(1 To lRows, 1 To lCols)

ReDim arrReturnData(1 To lRows, 1 To lCols)

'Set rngspace = Selection
arrdata = rngspace.Value

For q = 1 To lCols
For p = 1 To lRows
arrReturnData(p, q) = Trim(arrdata(p, q))
Next p
Next q

rngspace.Value = arrReturnData

Set rngspace.Value = Nothing
End Sub

Getting overflow error at bolded line(arrdata = rngspace.Value). Please check and help.

Subscribe To Our Newsletter!

The Best of CCM in Your Inbox

Subscribe To Our Newsletter!