一行ごとに編集

Option Explicit
Sub DelMacro()
'
' Macro2 Macro
'2018/08/09 列削除
'
Dim nRTN As Integer
 nRTN = MsgBox(“列を削除します。”, vbOKCancel)
 If nRTN = vbCancel Then Exit Sub

 Columns(“A:Y”).Select
 Selection.ClearContents

' Columns(“A:Y”).Select
' Range(“Y1”).Activate
' Selection.Delete Shift:=xlToLeft
' Range(“E1”).Select

Range(“A1”).Activate
MsgBox (“END”)

End Sub


Sub Macro1()

'2018/08/04
Dim i As Integer
Dim s決済区分 As String '0=未決済、1=決済済み
Dim nRTN As Integer
Dim iCount As Integer
Dim d成立日時 As Date
Dim d決済日時 As Date

nRTN = MsgBox(“「FX_FL」の「レポートの保存」を「Sheet1」にコピーした内容を更新します。”, vbOKCancel)
If nRTN = vbCancel Then Exit Sub
With Worksheets(“Sheet1”)
'見出し名セット
If .Cells(1, 15) = “” Then
.Cells(1, 15) = “MagicNO”
Else
MsgBox “見出しの15列が空白でない。整理Noをセットできません”
End If
If .Cells(1, 16) = “” Then
.Cells(1, 16) = “コメント”
Else
MsgBox “見出しの16列が空白でない。コメントをセットできません”
End If
If .Cells(1, 17) = “” Then
.Cells(1, 17) = “決済区分”
Else
MsgBox “見出しの17列が空白でない。決済区分をセットできません”

End If
If .Cells(1, 18) = “” Then
.Cells(1, 18) = “集計区分”
Else
MsgBox “見出しの18列が空白でない。集計区分をセットできません”

End If
If .Cells(1, 19) = “” Then
.Cells(1, 19) = “時間窓区分”
Else
MsgBox “見出しの19列が空白でない。時間窓区分をセットできません”

End If
If .Cells(1, 20) = “” Then
.Cells(1, 20) = “取消区分”
Else
MsgBox “見出しの20列が空白でない。時間窓区分をセットできません”

End If
If .Cells(1, 21) = “” Then
.Cells(1, 21) = “成立日”
Else
MsgBox “見出しの21列が空白でない。成立日をセットできません”

End If
If .Cells(1, 22) = “” Then
.Cells(1, 22) = “成立時間”
Else
MsgBox “見出しの22列が空白でない。成立時間をセットできません”

End If
If .Cells(1, 23) = “” Then
.Cells(1, 23) = “決済日”
Else
MsgBox “見出しの23列が空白でない。決済日をセットできません”

End If
If .Cells(1, 24) = “” Then
.Cells(1, 24) = “決済時間”
Else
MsgBox “見出しの24列が空白でない。決済時間をセットできません”

End If
If .Cells(1, 25) = “” Then
.Cells(1, 25) = “取引種別2”
Else
MsgBox “見出しの25列が空白でない。取引種別2をセットできません”

End If
'2018/08/30
If .Cells(1, 26) = “” Then
.Cells(1, 26) = “保有期間”
Else
MsgBox “見出しの26列が空白でない。保有期間をセットできません”

End If
iCount = 0
'マージセル解除
Columns(“K:N”).Select
Selection.UnMerge
Columns(“A:I”).Select
Selection.UnMerge
Columns(“A:J”).Select
Selection.UnMerge
Columns(“A:L”).Select
Selection.UnMerge
Range(“A1”).Activate
s決済区分 = 1
'行処理
For i = 2 To .Cells(.Rows.Count, 1).End(xlUp).Row

If .Cells(i, 1) = “” Then
If .Cells(i, 10) <> “” Then 'J 仕切りレート
.Cells(i - 1, 15) = .Cells(i, 10)
.Cells(i - 1, 16) = .Cells(i, 11)
' Else
' iCount = iCount + 1
End If
End If

'空白行削除
If .Cells(i, 1) = “” Then
Rows(i).Delete

End If
If Trim(.Cells(i, 3)) = “balance” Then
Rows(i).Delete
End If
If Left(Trim(.Cells(i, 3)), 2) = “ba” Then
Rows(i).Delete
End If

If Left(Trim(.Cells(i, 4)), 7) = “TRAN_ID” Then
Rows(i).Delete
End If

'金額の空白削除
.Cells(i, 13) = Replace(.Cells(i, 13), “ ”, “”)
.Cells(i, 14) = Replace(.Cells(i, 14), “ ”, “”)

'日時調整
.Cells(i, 2) = Replace(.Cells(i, 2), “.”, “/”)
.Cells(i, 9) = Replace(.Cells(i, 9), “.”, “/”)

.Cells(i, 17) = s決済区分

If Left(.Cells(i, 1), 1) = “チ” And i > 10 Then
' If .Cells(i, 1) = “チケット番号” And .Cells(i, 14) = “評価損益” And .Cells(i, 9) = “” Then

s決済区分 = 0

End If

If .Cells(i, 1) = “損益計:” Then
Rows(i).Delete
End If
If Left(.Cells(i, 1), 1) = “オ” Then
s決済区分 = 0
Rows(i).Delete
End If
' If .Cells(i, 1) = “チケット番号” And i > 1 Then
' Rows(i).Delete
' End If
If .Cells(i, 11) = “cancelled” Then
.Cells(i, 16) = .Cells(i, 11)
.Cells(i, 20) = 1
End If
If .Cells(i, 11) = “cancelled” Then
.Cells(i, 11) = “”
End If
'取引種別を取引種別2にセット
.Cells(i, 25) = .Cells(i, 3)

' If .Cells(i, 1) = “オープンポジション情報:” Then
' s決済区分 = 0
' End If

If IsDate(.Cells(i, 2)) Then
d成立日時 = DateAdd(“h”, .Cells(i, 2), 6)

.Cells(i, 21) = Year(d成立日時) & “/” & Month(d成立日時) & “/” & Day(d成立日時)
.Cells(i, 22) = Hour(d成立日時) & “:” & Minute(d成立日時)
Else
.Cells(i, 21) = “”
.Cells(i, 23) = “”

End If

If IsDate(.Cells(i, 9)) Then
d決済日時 = DateAdd(“h”, .Cells(i, 9), 6)
.Cells(i, 23) = Year(d決済日時) & “/” & Month(d決済日時) & “/” & Day(d決済日時)
.Cells(i, 24) = Hour(d決済日時) & “:” & Minute(d決済日時)
Else
.Cells(i, 23) = “”
.Cells(i, 24) = “”
End If

If .Cells(i, 11) = “評価損益計:” Then
Exit For
End If

If .Cells(i, 1) = “” And .Cells(i, 2) = “” And .Cells(i, 3) = “” And .Cells(i, 4) = “” And .Cells(i, 5) = “” Then
iCount = iCount + 1
If iCount > 3 Then
Exit For
End If
End If

' If iCount > 5 Then
' Exit For
' End If

Next i

.Cells(i, 1).Select
End With
'Range(“A1”).Activate
MsgBox (“END”)

End Sub