goss
Active Member
- Joined
- Feb 2, 2004
- Messages
- 372
Hi all,
I am try to unstack data I receive in an email as this
Inv Nmbr
Inv Date
Inv Amount
To this:
Inv Nmbr | Inv Date | Inv Amnt
My code below works for several rows of data and then returns an error on row 13
The only difference I see in the data:
Rec 1: 64.70
Rec 2: 0.00
Rec 3: -15.28
So it appears the negative amount may be causing the error, but I cannot figure out why?
Full code below
thanks
w
I am try to unstack data I receive in an email as this
Inv Nmbr
Inv Date
Inv Amount
To this:
Inv Nmbr | Inv Date | Inv Amnt
My code below works for several rows of data and then returns an error on row 13
The only difference I see in the data:
Rec 1: 64.70
Rec 2: 0.00
Rec 3: -15.28
So it appears the negative amount may be causing the error, but I cannot figure out why?
Full code below
thanks
w
Code:
Option Explicit
Sub GetTrxAmount()
Dim wbBook As Workbook
Dim wsData As Worksheet
Dim strFormula As String
Dim lngRows As Long
Dim C As Range
With Application
.ScreenUpdating = False
.DisplayAlerts = False
.Calculation = xlCalculationManual
End With
Set wbBook = ThisWorkbook
Set wsData = wbBook.Worksheets("Data")
lngRows = wsData.Range("A65536").End(xlUp).Row
strFormula = "=IF(ISERROR(FIND(""Amount"",OFFSET(A1,2,3))),0,VALUE(MID(OFFSET(A1,2,3),16,LEN(OFFSET(A1,2,3))-15)))"
With wsData
.Range("C1").EntireColumn.Insert
.Range("C1:C" & lngRows).Formula = strFormula
' .Range("C1:C" & lngRows).NumberFormat = "_(* #,##0.00_);_(* (#,##0.00);_(* " - "??_);_(@_)"
For Each C In .Range("C1:C" & lngRows)
C.Value = C.Value
Next C
End With
'Set Column Width
wsData.Columns("C").ColumnWidth = 12
'//Cleanup
Set wbBook = Nothing
Set wsData = Nothing
Set C = Nothing
With Application
.DisplayAlerts = False
.ScreenUpdating = False
.Calculation = xlCalculationAutomatic
End With
End Sub