Excel 2007 | |||||||||
---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | |||
1 | TRANSACTION_REF:ABC45678 | ||||||||
2 | SUM OF PAYMENT_AMOUNT:100000 | ||||||||
3 | PAYMENT_CCY:USD | ||||||||
4 | PAYMENT_VALUE_DATE:21/04/2017 | ||||||||
5 | |||||||||
6 | CODE | REF | COMPLETE DATE | TOTAL | CCY | PMT AMOUNT | FILE NAME | ||
7 | N | 11111111111 | 27/02/2017 | 1111 | USD | 1111 | INV55555555.CSV | ||
8 | N | 22222222222 | 27/02/2017 | 2222 | USD | 2222 | INV66666666.CSV | ||
9 | TRANSACTION_REF:ABC12345 | ||||||||
10 | SUM OF PAYMENT_AMOUNT:1618.26 | ||||||||
11 | PAYMENT_CCY:USD | ||||||||
12 | PAYMENT_VALUE_DATE:21/04/2017 | ||||||||
13 | |||||||||
14 | CODE | REF | COMPLETE DATE | TOTAL | CCY | PMT AMOUNT | FILE NAME | ||
15 | N | 33333333333 | 42979 | 3333 | USD | 3333 | INV66666666.CSV | ||
16 | |||||||||
Sheet1 |
Excel 2007 | |||||||||
---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | |||
1 | ABC45678 | 11111111111 | 27/02/2017 | 1111 | USD | 1111 | INV55555555.CSV | ||
2 | ABC45678 | 22222222222 | 27/02/2017 | 2222 | USD | 2222 | INV66666666.CSV | ||
3 | ABC12345 | 33333333333 | 42979 | 3333 | USD | 3333 | INV66666666.CSV | ||
4 | |||||||||
5 | |||||||||
6 | |||||||||
7 | |||||||||
8 | |||||||||
9 | |||||||||
10 | |||||||||
11 | |||||||||
12 | |||||||||
13 | |||||||||
14 | |||||||||
15 | |||||||||
16 | |||||||||
Sheet1 |
Sub max_cali_V3()
' hiker95, 04/25/2017, ME300330
Dim lr As Long, r As Range, t As String
Application.ScreenUpdating = False
With ActiveSheet
lr = .Cells(Rows.Count, 1).End(xlUp).Row
With .Range("A1:A" & lr)
.Replace "SUM OF PAYMENT_AMOUNT*", "#N/A", xlWhole, , False
.Replace "PAYMENT_CCY*", "#N/A", xlWhole, , False
.Replace "PAYMENT_VALUE_DATE*", "#N/A", xlWhole, , False
.Replace "CODE", "#N/A", xlWhole, , False
.Replace "", "#N/A", xlWhole, , False
End With
On Error Resume Next
.Columns("A").SpecialCells(xlConstants, xlErrors).EntireRow.Delete
On Error GoTo 0
lr = .Cells(Rows.Count, 1).End(xlUp).Row
For Each r In .Range("A1:A" & lr)
If InStr(r, "TRANSACTION_REF:") Then
t = Right(r, Len(r) - 16)
ElseIf r = "N" Then
r = t
End If
Next r
With .Range("A1:A" & lr)
.Replace "TRANSACTION_REF*", "#N/A", xlWhole, , False
End With
On Error Resume Next
.Columns("A").SpecialCells(xlConstants, xlErrors).EntireRow.Delete
On Error GoTo 0
.Columns(1).AutoFit
End With
Application.ScreenUpdating = True
End Sub
Here is another way to write your macro...Code:Sub max_cali_V2() ' hiker95, 04/24/2017, ME300330 Dim lr As Long Application.ScreenUpdating = False With ActiveSheet lr = .Cells(Rows.Count, 1).End(xlUp).Row With .Range("A1:A" & lr) .Replace "TRANSACTION_REF*", "#N/A", xlWhole, , False .Replace "SUM OF PAYMENT_AMOUNT*", "#N/A", xlWhole, , False .Replace "PAYMENT_CCY*", "#N/A", xlWhole, , False .Replace "PAYMENT_VALUE_DATE*", "#N/A", xlWhole, , False .Replace "CODE", "#N/A", xlWhole, , False .Replace "", "#N/A", xlWhole, , False End With On Error Resume Next .Columns("A").SpecialCells(xlConstants, xlErrors).EntireRow.Delete On Error GoTo 0 .Columns(1).AutoFit End With Application.ScreenUpdating = True End Sub
[table="width: 500"]
[tr]
[td]Sub max_cali_V3()
Dim LastRow As Long
With ActiveSheet
LastRow = .Cells.Find("*", , xlValues, , xlRows, xlPrevious).Row
.Range("B1:B" & LastRow).SpecialCells(xlConstants, xlNumbers).EntireRow.Copy .Cells(LastRow + 1, "A")
.Rows("1:" & LastRow).Delete
.Columns(1).AutoFit
End With
End Sub[/td]
[/tr]
[/table]
Hi hiker95, it's totally perfect, the result is what I expect. By the way, can we adjust the code to automatically input the transaction reference (e.g. ABC45678 in cell A1, ABC12345 in cell A9) to the next columns "file name".
I'm using windows 7, Excel 2010. Thank you for your kind help.
Excel 2007 | |||||||||
---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | |||
1 | TRANSACTION_REF:ABC45678 | ||||||||
2 | SUM OF PAYMENT_AMOUNT:100000 | ||||||||
3 | PAYMENT_CCY:USD | ||||||||
4 | PAYMENT_VALUE_DATE:21/04/2017 | ||||||||
5 | |||||||||
6 | CODE | REF | COMPLETE DATE | TOTAL | CCY | PMT AMOUNT | FILE NAME | ||
7 | N | 11111111111 | 27/02/2017 | 1111 | USD | 1111 | INV55555555.CSV | ||
8 | N | 22222222222 | 27/02/2017 | 2222 | USD | 2222 | INV66666666.CSV | ||
9 | TRANSACTION_REF:ABC12345 | ||||||||
10 | SUM OF PAYMENT_AMOUNT:1618.26 | ||||||||
11 | PAYMENT_CCY:USD | ||||||||
12 | PAYMENT_VALUE_DATE:21/04/2017 | ||||||||
13 | |||||||||
14 | CODE | REF | COMPLETE DATE | TOTAL | CCY | PMT AMOUNT | FILE NAME | ||
15 | N | 33333333333 | 42979 | 3333 | USD | 3333 | INV66666666.CSV | ||
16 | |||||||||
Sheet1 |
Excel 2007 | |||||||||
---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | |||
1 | N | 11111111111 | 27/02/2017 | 1111 | USD | 1111 | ABC45678 | ||
2 | N | 22222222222 | 27/02/2017 | 2222 | USD | 2222 | ABC45678 | ||
3 | N | 33333333333 | 42979 | 3333 | USD | 3333 | ABC12345 | ||
4 | |||||||||
Sheet1 |
Sub max_cali_V4()
' hiker95, 04/25/2017, ME300330
Dim lr As Long, r As Range, t As String
Application.ScreenUpdating = False
With ActiveSheet
lr = .Cells(Rows.Count, 1).End(xlUp).Row
With .Range("A1:A" & lr)
.Replace "SUM OF PAYMENT_AMOUNT*", "#N/A", xlWhole, , False
.Replace "PAYMENT_CCY*", "#N/A", xlWhole, , False
.Replace "PAYMENT_VALUE_DATE*", "#N/A", xlWhole, , False
.Replace "CODE", "#N/A", xlWhole, , False
.Replace "", "#N/A", xlWhole, , False
End With
On Error Resume Next
.Columns("A").SpecialCells(xlConstants, xlErrors).EntireRow.Delete
On Error GoTo 0
lr = .Cells(Rows.Count, 1).End(xlUp).Row
For Each r In .Range("A1:A" & lr)
If InStr(r, "TRANSACTION_REF:") Then
t = Right(r, Len(r) - 16)
ElseIf r = "N" Then
r.Offset(, 6) = t
End If
Next r
With .Range("A1:A" & lr)
.Replace "TRANSACTION_REF*", "#N/A", xlWhole, , False
End With
On Error Resume Next
.Columns("A").SpecialCells(xlConstants, xlErrors).EntireRow.Delete
On Error GoTo 0
.Columns("A:G").AutoFit
End With
Application.ScreenUpdating = True
End Sub
Here is how I would modify the code I posted in Message #162 to do this...I missed that part, from your reply #158.Hi hiker95, it's totally perfect, the result is what I expect. By the way, can we adjust the code to automatically input the transaction reference (e.g. ABC45678 in cell A1, ABC12345 in cell A9) to the next columns "file name".
I'm using windows 7, Excel 2010. Thank you for your kind help.
max_cali,
Code:Sub max_cali_V4() ' hiker95, 04/25/2017, ME300330 Dim lr As Long, r As Range, t As String Application.ScreenUpdating = False With ActiveSheet lr = .Cells(Rows.Count, 1).End(xlUp).Row With .Range("A1:A" & lr) .Replace "SUM OF PAYMENT_AMOUNT*", "#N/A", xlWhole, , False .Replace "PAYMENT_CCY*", "#N/A", xlWhole, , False .Replace "PAYMENT_VALUE_DATE*", "#N/A", xlWhole, , False .Replace "CODE", "#N/A", xlWhole, , False .Replace "", "#N/A", xlWhole, , False End With On Error Resume Next .Columns("A").SpecialCells(xlConstants, xlErrors).EntireRow.Delete On Error GoTo 0 lr = .Cells(Rows.Count, 1).End(xlUp).Row For Each r In .Range("A1:A" & lr) If InStr(r, "TRANSACTION_REF:") Then t = Right(r, Len(r) - 16) ElseIf r = "N" Then r.Offset(, 6) = t End If Next r With .Range("A1:A" & lr) .Replace "TRANSACTION_REF*", "#N/A", xlWhole, , False End With On Error Resume Next .Columns("A").SpecialCells(xlConstants, xlErrors).EntireRow.Delete On Error GoTo 0 .Columns("A:G").AutoFit End With Application.ScreenUpdating = True End Sub
[table="width: 500"]
[tr]
[td]Sub max_cali_V3revised()
Dim X As Long, LastRow As Long, LastCol As Long, TRANS As Range, REFs As Range
LastRow = Cells.Find("*", , xlValues, , xlRows, xlPrevious).Row
LastCol = Cells.Find("*", , xlValues, , xlColumns, xlPrevious).Column
Application.ScreenUpdating = False
With Range("B1:B" & LastRow)
.Value = Evaluate(Replace("IF(LEFT(@,11)=""TRANSACTION"",RIGHT(@,8),IF(@=""N""," & .Address & ",""""))", "@", .Offset(, -1).Address))
Set TRANS = .SpecialCells(xlConstants, xlTextValues)
Set REFs = .SpecialCells(xlConstants, xlNumbers)
For X = 1 To REFs.Areas.Count
Intersect(REFs.Areas(X).EntireRow, Columns(LastCol + 1)) = TRANS.Areas(X)(1).Value
Next
.SpecialCells(xlConstants, xlNumbers).EntireRow.Copy Cells(LastRow + 1, "A")
End With
Rows("1:" & LastRow).Delete
Columns("A").AutoFit
Application.ScreenUpdating = True
End Sub[/td]
[/tr]
[/table]
You cannot test for an error cell that way, try it this way...I came across your code, modified it slightly (below) but i'm receiving a Run-time error '13' Type Mismatch message. What have I done incorrectly?
If (Cells(i, "E").Value) = "#N/A" Then