' change log:

Option Explicit

Dim first_row As Integer
Dim current_row As Integer
Dim last_check_row As Integer

Dim ADJUSTMENT_WORKSHEET As String
Dim BMF_ADJUSTMENT_WORKSHEET As String

' BALANCE_SHEET
Dim COL_BALANCE_SHEET_NA_1 As String
Dim COL_BALANCE_SHEET_PCCO_1 As String
Dim COL_BALANCE_SHEET_AMOUNT_TO_ADJ_1 As String

Dim COL_BALANCE_SHEET_NA_2 As String
Dim COL_BALANCE_SHEET_PCCO_2 As String
Dim COL_BALANCE_SHEET_AMOUNT_TO_ADJ_2 As String

' OFF_BALANCE_SHEET
Dim COL_OFF_BALANCE_SHEET_NA_1 As String
Dim COL_OFF_BALANCE_SHEET_PCCO_1 As String
Dim COL_OFF_BALANCE_SHEET_AMOUNT_TO_ADJ_1 As String

Dim COL_OFF_BALANCE_SHEET_NA_2 As String
Dim COL_OFF_BALANCE_SHEET_PCCO_2 As String
Dim COL_OFF_BALANCE_SHEET_AMOUNT_TO_ADJ_2 As String

Dim COL_FINAL_BMF_ID As String

Dim COL_BMF_ADJUSTMENT_SHEET_BMF_REFERENCE_ID As String
Dim COL_BMF_ADJUSTMENT_SHEET_LINE_TYPE As String
Dim COL_BMF_ADJUSTMENT_SHEET_ADJUSTMENT_ID As String
Dim COL_BMF_ADJUSTMENT_SHEET_ADJUSTMENT_TYPE As String
Dim COL_BMF_ADJUSTMENT_SHEET_COMMENT As String
Dim COL_BMF_ADJUSTMENT_SHEET_REPORTING_ENTITY As String
Dim COL_BMF_ADJUSTMENT_SHEET_PCCO As String
Dim COL_BMF_ADJUSTMENT_SHEET_PCEC As String
Dim COL_BMF_ADJUSTMENT_SHEET_ACCOUNTING_BALANCE_CURRENCY As String
Dim COL_BMF_ADJUSTMENT_SHEET_AMOUNT_IN_ACCT_BALANCE As String
Dim COL_BMF_ADJUSTMENT_SHEET_AMOUNT_IN_FUNT As String
Dim COL_BMF_ADJUSTMENT_SHEET_FAIR_VALUE As String
Dim COL_BMF_ADJUSTMENT_SHEET_ECONOMIC_AGENT As String
Dim COL_BMF_ADJUSTMENT_SHEET_OPAQUE_REPORTING_ENTITY As String
Dim COL_BMF_ADJUSTMENT_SHEET_REMAINING_MATURITY As String
Dim COL_BMF_ADJUSTMENT_SHEET_IFRS13 As String
Dim COL_BMF_ADJUSTMENT_SHEET_COUNTRY As String
Dim COL_BMF_ADJUSTMENT_SHEET_LOCAL_OPERATIONAL_ACCOUNT As String

Dim RED_THOUSAND_SEP_NUMBER_FORMAT as string

Sub init()
  On Error GoTo eh

  RED_THOUSAND_SEP_NUMBER_FORMAT = "#,##0_);[Red](#,##0)"

  ' HEADER_ROW = 6
  first_row = 6
  current_row = first_row
  last_check_row = 9999

  ' ADJUSTMENT_SHEET
  ADJUSTMENT_WORKSHEET = "Adjustment"
  
  ' BALANCE_SHEET
  COL_BALANCE_SHEET_NA_1 = "Q"
  COL_BALANCE_SHEET_PCCO_1 = "R"
  COL_BALANCE_SHEET_AMOUNT_TO_ADJ_1 = "S"

  COL_BALANCE_SHEET_NA_2 = "T"
  COL_BALANCE_SHEET_PCCO_2 = "U"
  COL_BALANCE_SHEET_AMOUNT_TO_ADJ_2 = "V"

  ' OFF_BALANCE_SHEET
  COL_OFF_BALANCE_SHEET_NA_1 = "X"
  COL_OFF_BALANCE_SHEET_PCCO_1 = "Y"
  COL_OFF_BALANCE_SHEET_AMOUNT_TO_ADJ_1 = "Z"

  COL_OFF_BALANCE_SHEET_NA_2 = "AA"
  COL_OFF_BALANCE_SHEET_PCCO_2 = "AB"
  COL_OFF_BALANCE_SHEET_AMOUNT_TO_ADJ_2 = "AC"

  COL_FINAL_BMF_ID = "AI"

  ' BMF_ADJUSTMENT_SHEET
  BMF_ADJUSTMENT_WORKSHEET = "BMF Adjustment"
  COL_BMF_ADJUSTMENT_SHEET_BMF_REFERENCE_ID = "A"
  COL_BMF_ADJUSTMENT_SHEET_LINE_TYPE = "B"
  COL_BMF_ADJUSTMENT_SHEET_ADJUSTMENT_ID = "C"
  COL_BMF_ADJUSTMENT_SHEET_ADJUSTMENT_TYPE = "D"
  COL_BMF_ADJUSTMENT_SHEET_COMMENT = "E"
  COL_BMF_ADJUSTMENT_SHEET_REPORTING_ENTITY = "F"
  COL_BMF_ADJUSTMENT_SHEET_PCCO = "G"
  COL_BMF_ADJUSTMENT_SHEET_PCEC = "H"
  COL_BMF_ADJUSTMENT_SHEET_ACCOUNTING_BALANCE_CURRENCY = "I"
  COL_BMF_ADJUSTMENT_SHEET_AMOUNT_IN_ACCT_BALANCE = "J"
  COL_BMF_ADJUSTMENT_SHEET_AMOUNT_IN_FUNT = "K"
  COL_BMF_ADJUSTMENT_SHEET_FAIR_VALUE = "BH"
  COL_BMF_ADJUSTMENT_SHEET_ECONOMIC_AGENT = "BI"
  COL_BMF_ADJUSTMENT_SHEET_OPAQUE_REPORTING_ENTITY = "BJ"
  COL_BMF_ADJUSTMENT_SHEET_REMAINING_MATURITY = "BK"
  COL_BMF_ADJUSTMENT_SHEET_IFRS13 = "BL"
  COL_BMF_ADJUSTMENT_SHEET_COUNTRY = "BM"
  COL_BMF_ADJUSTMENT_SHEET_LOCAL_OPERATIONAL_ACCOUNT = "BN"

Done:
  Debug.Print "init done"
  Exit Sub

eh:
  Debug.Print "init:Error: " & Err.Description


End Sub

function paintYellow(cell as variant)
  cell.Interior.Color = rgb(246, 229, 141)
  paintYellow = True
end function

function paintRed(cell as variant)
  cell.Interior.Color = rgb(255, 121, 121)
  paintRed = True
end function

Function CheckIfOffBalanceSheetAmountToAdjust1NoNeedCopy(current_row As Integer, bmf_id As String, pcco As String)
  On Error GoTo eh
  Dim output As Boolean
  output = False
  Dim temp As String
  temp = Worksheets(ADJUSTMENT_WORKSHEET).Range(COL_OFF_BALANCE_SHEET_AMOUNT_TO_ADJ_1 & CStr(current_row)).Value

  If ( temp = "") Then
    output = True
  ElseIf (temp = "0") Then
    paintYellow(Worksheets(ADJUSTMENT_WORKSHEET).Range(COL_OFF_BALANCE_SHEET_AMOUNT_TO_ADJ_1 & CStr(current_row)))
    output = True
  ElseIf (checkIfAlreadyExistInBmfAdjustmentResult(bmf_id, pcco, current_row)) Then
    paintRed(Worksheets(ADJUSTMENT_WORKSHEET).Range("AI" & CStr(current_row)))
    paintRed(Worksheets(ADJUSTMENT_WORKSHEET).Range(COL_OFF_BALANCE_SHEET_PCCO_1 & CStr(current_row)))
    
    output = True
  End If


  CheckIfOffBalanceSheetAmountToAdjust1NoNeedCopy = output

Done:
  Exit Function

eh:
  Debug.Print "CheckIfOffBalanceSheetAmountToAdjust1NoNeedCopy:Error: " & Err.Description

End Function

Function CheckIfAdjustmentSheetBmfIdValid(current_row As Integer)
  On Error GoTo eh
  Dim output As Boolean
  output = False
  Dim temp As String
  temp = Worksheets(ADJUSTMENT_WORKSHEET).Range(COL_FINAL_BMF_ID & CStr(current_row)).Value

  If (temp <> "") Then
    output = True
  End If

  CheckIfAdjustmentSheetBmfIdValid = output

Done:
  Exit Function

eh:
  Debug.Print "CheckIfAdjustmentSheetBmfIdValid:Error: " & Err.Description

End Function



Function CheckIfOffBalanceSheetAmountToAdjust2NoNeedCopy(current_row As Integer, bmf_id As String, pcco As String)
  On Error GoTo eh
  Dim output As Boolean
  output = False
  Dim temp As String
  temp = Worksheets(ADJUSTMENT_WORKSHEET).Range(COL_OFF_BALANCE_SHEET_AMOUNT_TO_ADJ_2 & CStr(current_row)).Value

  If ( temp = "") Then
    output = True
  ElseIf (temp = "0") Then
    paintYellow(Worksheets(ADJUSTMENT_WORKSHEET).Range(COL_OFF_BALANCE_SHEET_AMOUNT_TO_ADJ_2 & CStr(current_row)))
    output = True
  ElseIf (checkIfAlreadyExistInBmfAdjustmentResult(bmf_id, pcco, current_row)) Then
    paintRed(Worksheets(ADJUSTMENT_WORKSHEET).Range("AI" & CStr(current_row)))
    paintRed(Worksheets(ADJUSTMENT_WORKSHEET).Range(COL_OFF_BALANCE_SHEET_PCCO_2 & CStr(current_row)))
    output = True
  End If


  CheckIfOffBalanceSheetAmountToAdjust2NoNeedCopy = output

Done:
  Exit Function

eh:
  Debug.Print "CheckIfOffBalanceSheetAmountToAdjust2NoNeedCopy:Error: " & Err.Description

End Function


Function CheckIfBalanceSheetAmountToAdjust1NoNeedCopy(current_row As Integer, bmf_id As String, pcco As String)
  On Error GoTo eh
  Dim output As Boolean
  output = False
  
  Dim temp As String

  temp = Worksheets(ADJUSTMENT_WORKSHEET).Range(COL_BALANCE_SHEET_AMOUNT_TO_ADJ_1 & CStr(current_row)).Value
  Debug.Print "CheckIfBalanceSheetAmountToAdjust1NoNeedCopy:" & temp = "0"

  If ( temp = "") Then
    output = True
  ElseIf (temp = "0") Then
    paintYellow(Worksheets(ADJUSTMENT_WORKSHEET).Range(COL_BALANCE_SHEET_AMOUNT_TO_ADJ_1 & CStr(current_row)))
    output = True
  ElseIf (checkIfAlreadyExistInBmfAdjustmentResult(bmf_id, pcco, current_row)) Then
    paintRed(Worksheets(ADJUSTMENT_WORKSHEET).Range("AI" & CStr(current_row)))
    paintRed(Worksheets(ADJUSTMENT_WORKSHEET).Range(COL_BALANCE_SHEET_PCCO_1 & CStr(current_row)))
    output = True
  End If

  CheckIfBalanceSheetAmountToAdjust1NoNeedCopy = output

Done:
  Exit Function

eh:
  Debug.Print "CheckIfBalanceSheetAmountToAdjust1NoNeedCopy:Error: " & Err.Description

End Function

Function CheckIfBalanceSheetAmountToAdjust2NoNeedCopy(current_row As Integer, bmf_id As String, pcco As String)
  On Error GoTo eh
  Dim output As Boolean
  output = False
  Dim temp As String
  temp = Worksheets(ADJUSTMENT_WORKSHEET).Range(COL_BALANCE_SHEET_AMOUNT_TO_ADJ_2 & CStr(current_row)).Value

  If ( temp = "") Then
    output = True
  ElseIf (temp = "0") Then
    paintYellow(Worksheets(ADJUSTMENT_WORKSHEET).Range(COL_BALANCE_SHEET_AMOUNT_TO_ADJ_2 & CStr(current_row)))
    output = True
  ElseIf (checkIfAlreadyExistInBmfAdjustmentResult(bmf_id, pcco, current_row)) Then
    paintRed(Worksheets(ADJUSTMENT_WORKSHEET).Range("AI" & CStr(current_row)))
    paintRed(Worksheets(ADJUSTMENT_WORKSHEET).Range(COL_BALANCE_SHEET_PCCO_2 & CStr(current_row)))
    output = True
  End If


  CheckIfBalanceSheetAmountToAdjust2NoNeedCopy = output

Done:
  Exit Function

eh:
  Debug.Print "CheckIfBalanceSheetAmountToAdjust2NoNeedCopy:Error: " & Err.Description

End Function



Function CheckIfBalanceSheetNa2Exist(current_row As Integer)
  On Error GoTo eh
  Dim output As Boolean
  output = False
  Dim temp As String
  temp = Worksheets(ADJUSTMENT_WORKSHEET).Range(COL_BALANCE_SHEET_NA_2 & CStr(current_row)).Value

  If (temp <> "") Then
    output = True
  End If

  CheckIfBalanceSheetNa2Exist = output

Done:
  Exit Function

eh:
  Debug.Print "CheckIfBalanceSheetNa2Exist:Error: " & Err.Description

End Function

Function CheckIfBalanceSheetPcco2Exist(current_row As Integer)
  On Error GoTo eh

  Dim output As Boolean
  output = False
  Dim temp As String
  temp = Worksheets(ADJUSTMENT_WORKSHEET).Range(COL_BALANCE_SHEET_PCCO_2 & CStr(current_row)).Value

  If (temp <> "") Then
    output = True
  End If

  CheckIfBalanceSheetPcco2Exist = output

Done:
  Exit Function

eh:
  Debug.Print "CheckIfBalanceSheetPcco2Exist:Error: " & Err.Description

End Function

Function CheckIfBalanceSheetAmountToAdjust2Exist(current_row As Integer)
  On Error GoTo eh

  Dim output As Boolean
  output = False
  Dim temp As String
  temp = Worksheets(ADJUSTMENT_WORKSHEET).Range(COL_BALANCE_SHEET_AMOUNT_TO_ADJ_2 & CStr(current_row)).Value

  If (temp <> "") Then
    output = True
  End If

  CheckIfBalanceSheetAmountToAdjust2Exist = output

Done:
  Exit Function

eh:
  Debug.Print "CheckIfBalanceSheetAmountToAdjust2Exist:Error: " & Err.Description

End Function

Function isCurrentRowNeedToProcess(input_row As Integer)
  On Error GoTo eh

  Dim output As Boolean
  Dim cell_value As Currency
  Dim input_cell As String
  input_cell = GRANDTOTAL_COL & input_row

Done:
  isCurrentRowNeedToProcess = Not (IsEmpty(Worksheets(ADJUSTMENT_WORKSHEET).Range(input_cell).Value))
  Exit Function

eh:
  Debug.Print "isCurrentRowNeedToProcess:Error: " & Err.Description

End Function

Function getLastCheckRow(first_row As Integer)
  On Error GoTo eh
  getLastCheckRow = first_row + 10

Done:
  Exit Function

eh:
  Debug.Print "getLastCheckRow:Error: " & Err.Description

End Function

Function checkAdjustmentSheetLastRow(current_row As Integer)
  On Error GoTo eh
  Dim output As Boolean
  output = True

  Dim j As Integer
  Dim temp As String

  For j = current_row To getLastCheckRow(current_row)
    temp = Worksheets(ADJUSTMENT_WORKSHEET).Range(COL_FINAL_BMF_ID & CStr(current_row)).Value
    If (temp <> "") Then
      output = False
    End If
  Next j
  
  checkAdjustmentSheetLastRow = output

Done:
  Exit Function

eh:
  Debug.Print "checkAdjustmentSheetLastRow:Error: " & Err.Description

End Function

Function checkBmfAdjustmentSheetLastRow(current_row As Integer)
  On Error GoTo eh
  Dim output As Boolean
  output = True

  Dim j As Integer
  Dim temp As String

  For j = current_row To getLastCheckRow(current_row)
    temp = Worksheets(BMF_ADJUSTMENT_WORKSHEET).Range(COL_BMF_ADJUSTMENT_SHEET_BMF_REFERENCE_ID & CStr(current_row)).Value
    If (temp <> "") Then
      output = False
    End If
  Next j
  
  checkBmfAdjustmentSheetLastRow = output

Done:
  Exit Function

eh:
  Debug.Print "checkBmfAdjustmentSheetLastRow:Error: " & Err.Description

End Function

Function checkIfAlreadyExistInBmfAdjustmentResult(adj_bmf_id As String, adj_pcco As String, adj_sheet_row As Integer)
  On Error GoTo eh

  Dim i As Integer
  Dim bmf_adjustment_sheet_last_row As Integer
  Dim found As Boolean
  found = False
  Dim temp_value As String
  Dim bmf_adj_bmf_id As String
  Dim bmf_adj_pcco As String

  Application.ScreenUpdating = False


  bmf_adjustment_sheet_last_row = getBMFAdjustmentResultListEnd(1)

  For i = 1 To bmf_adjustment_sheet_last_row
    bmf_adj_bmf_id = Worksheets(BMF_ADJUSTMENT_WORKSHEET).Range(COL_BMF_ADJUSTMENT_SHEET_BMF_REFERENCE_ID & CStr(i)).Value
    bmf_adj_pcco = Worksheets(BMF_ADJUSTMENT_WORKSHEET).Range(COL_BMF_ADJUSTMENT_SHEET_PCCO & CStr(i)).Value

    ' debug.print bmf_adj_bmf_id
    ' debug.print bmf_adj_pcco
    ' debug.print adj_bmf_id
    ' debug.print adj_pcco
    ' debug.print bmf_adj_bmf_id = adj_bmf_id And bmf_adj_pcco = adj_pcco


    If (bmf_adj_bmf_id = adj_bmf_id And bmf_adj_pcco = adj_pcco) Then

      ' Worksheets(BMF_ADJUSTMENT_WORKSHEET).Range("B"&cstr(i)).value = Cstr(bmf_adj_bmf_id = adj_bmf_id)
      ' Worksheets(BMF_ADJUSTMENT_WORKSHEET).Range("B"&cstr(i)).value = Cstr(bmf_adj_pcco = adj_pcco)
      
      'Worksheets(BMF_ADJUSTMENT_WORKSHEET).Range(COL_BMF_ADJUSTMENT_SHEET_BMF_REFERENCE_ID & CStr(i)).Interior.Color = RGB(214, 48, 49)
      paintRed(Worksheets(BMF_ADJUSTMENT_WORKSHEET).Range(COL_BMF_ADJUSTMENT_SHEET_BMF_REFERENCE_ID & CStr(i)))
      ' Worksheets(BMF_ADJUSTMENT_WORKSHEET).Range(COL_BMF_ADJUSTMENT_SHEET_PCCO & CStr(i)).Interior.Color = RGB(214, 48, 49)
      paintred(Worksheets(BMF_ADJUSTMENT_WORKSHEET).Range(COL_BMF_ADJUSTMENT_SHEET_PCCO & CStr(i)))

      ' adj_sheet_row
 
      
      found = True

      Exit For
    End If
  Next i

  checkIfAlreadyExistInBmfAdjustmentResult = found

  Application.ScreenUpdating = True

Done:
  Exit Function

eh:
  Application.ScreenUpdating = True

  Debug.Print "checkIfAlreadyExistInBmfAdjustmentResult:Error: " & Err.Description

End Function

Function getBMFAdjustmentResultListEnd(start_row As Integer)
  On Error GoTo eh

  Dim i As Integer

  Dim last_row As Boolean
  Dim last_row_found As Boolean
  last_row_found = False
  last_row = True
  current_row = start_row

  For i = start_row To 9999
    current_row = i
    last_row_found = checkBmfAdjustmentSheetLastRow(current_row)

    If (last_row_found = True) Then
      Exit For
    End If
  Next i

  getBMFAdjustmentResultListEnd = current_row - 1

Done:
  Exit Function

eh:
  Debug.Print "getBMFAdjustmentResultListEnd:Error: " & Err.Description

End Function

Function getAdjustmentSheetListEnd(start_row As Integer)
  On Error GoTo eh

  Dim i As Integer

  Dim last_row As Boolean
  Dim last_row_found As Boolean
  last_row_found = False
  last_row = True
  current_row = start_row

  For i = start_row To 9999
    current_row = i
    last_row_found = checkAdjustmentSheetLastRow(current_row)

    If (last_row_found = True) Then
      Exit For
    End If
  Next i

  getAdjustmentSheetListEnd = current_row - 1

Done:
  Exit Function

eh:
  Debug.Print "getAdjustmentSheetListEnd:Error: " & Err.Description

End Function


Sub resetBmfAdjustmentSheet()
  init
  Worksheets(BMF_ADJUSTMENT_WORKSHEET).Range("A4:BN9999").Clear

end sub

Sub helloworld()
  On Error GoTo eh
  Dim need_to_copy As Boolean

  Dim adjustment_sheet_first_row As Integer
  Dim adjustment_sheet_last_row As Integer
  Dim adjustment_sheet_current_row As Integer

  Dim bmf_adjustment_sheet_last_row As Integer
  Dim bmf_adjustment_sheet_current_row As Integer

  Dim temp_value As String

  adjustment_sheet_first_row = 7

  init
  ' MsgBox "helloworld"
  adjustment_sheet_last_row = getAdjustmentSheetListEnd(adjustment_sheet_first_row)
  Debug.Print adjustment_sheet_last_row

  For adjustment_sheet_current_row = adjustment_sheet_first_row To adjustment_sheet_last_row
    Debug.Print "processing adjustment_sheet_current_row: " & adjustment_sheet_current_row

    ' if (CheckIfBalanceSheetAmountToAdjust2Exist(adjustment_sheet_current_row) and CheckIfBalanceSheetNa2Exist(adjustment_sheet_current_row) and CheckIfBalanceSheetPcco2Exist(adjustment_sheet_current_row)) then
    If (CheckIfAdjustmentSheetBmfIdValid(adjustment_sheet_current_row)) Then
      Debug.Print "processing row: " & adjustment_sheet_current_row

      Dim bmf_id As String
      bmf_id = Worksheets(ADJUSTMENT_WORKSHEET).Range(COL_FINAL_BMF_ID & CStr(adjustment_sheet_current_row)).Value

      Dim bal_pcco_1 As String
      bal_pcco_1 = Worksheets(ADJUSTMENT_WORKSHEET).Range(COL_BALANCE_SHEET_PCCO_1 & CStr(adjustment_sheet_current_row)).Value

      Dim bal_pcco_2 As String
      bal_pcco_2 = Worksheets(ADJUSTMENT_WORKSHEET).Range(COL_BALANCE_SHEET_PCCO_2 & CStr(adjustment_sheet_current_row)).Value

      Dim off_bal_pcco_1 As String
      off_bal_pcco_1 = Worksheets(ADJUSTMENT_WORKSHEET).Range(COL_OFF_BALANCE_SHEET_PCCO_1 & CStr(adjustment_sheet_current_row)).Value

      Dim off_bal_pcco_2 As String
      off_bal_pcco_2 = Worksheets(ADJUSTMENT_WORKSHEET).Range(COL_OFF_BALANCE_SHEET_PCCO_2 & CStr(adjustment_sheet_current_row)).Value

      ' balance sheet 1
      ' check need to copy ? see amount to adjust <> 0 ?
      If (CheckIfBalanceSheetAmountToAdjust1NoNeedCopy(adjustment_sheet_current_row, bmf_id, bal_pcco_1) = True) Then
        ' do skip
        Debug.Print "skip balance sheet 1"
      Else
        ' do copy
        bmf_adjustment_sheet_last_row = getBMFAdjustmentResultListEnd(1)
        bmf_adjustment_sheet_current_row = bmf_adjustment_sheet_last_row + 1
        Debug.Print "bmf_adjustment_sheet_current_row:" & bmf_adjustment_sheet_current_row

        temp_value = Worksheets(ADJUSTMENT_WORKSHEET).Range(COL_FINAL_BMF_ID & CStr(adjustment_sheet_current_row)).Value
        Worksheets(BMF_ADJUSTMENT_WORKSHEET).Range(COL_BMF_ADJUSTMENT_SHEET_BMF_REFERENCE_ID & CStr(bmf_adjustment_sheet_current_row)).Value = temp_value
        Worksheets(BMF_ADJUSTMENT_WORKSHEET).Range(COL_BMF_ADJUSTMENT_SHEET_REPORTING_ENTITY & CStr(bmf_adjustment_sheet_current_row)).Value = "14004"
        Worksheets(BMF_ADJUSTMENT_WORKSHEET).Range(COL_BMF_ADJUSTMENT_SHEET_OPAQUE_REPORTING_ENTITY & CStr(bmf_adjustment_sheet_current_row)).Value = "N"

        temp_value = Worksheets(ADJUSTMENT_WORKSHEET).Range(COL_BALANCE_SHEET_PCCO_1 & CStr(adjustment_sheet_current_row)).Value
        Worksheets(BMF_ADJUSTMENT_WORKSHEET).Range(COL_BMF_ADJUSTMENT_SHEET_PCCO & CStr(bmf_adjustment_sheet_current_row)).Value = temp_value

        temp_value = Worksheets(ADJUSTMENT_WORKSHEET).Range(COL_BALANCE_SHEET_AMOUNT_TO_ADJ_1 & CStr(adjustment_sheet_current_row)).Value
        Worksheets(BMF_ADJUSTMENT_WORKSHEET).Range(COL_BMF_ADJUSTMENT_SHEET_AMOUNT_IN_ACCT_BALANCE & CStr(bmf_adjustment_sheet_current_row)).Value = temp_value
        Worksheets(BMF_ADJUSTMENT_WORKSHEET).Range(COL_BMF_ADJUSTMENT_SHEET_AMOUNT_IN_FUNT & CStr(bmf_adjustment_sheet_current_row)).Value = temp_value

        temp_value = Worksheets(ADJUSTMENT_WORKSHEET).Range(COL_BALANCE_SHEET_NA_1 & CStr(adjustment_sheet_current_row)).Value
        Worksheets(BMF_ADJUSTMENT_WORKSHEET).Range(COL_BMF_ADJUSTMENT_SHEET_LOCAL_OPERATIONAL_ACCOUNT & CStr(bmf_adjustment_sheet_current_row)).Value = temp_value & " " & "15130"

        Worksheets(BMF_ADJUSTMENT_WORKSHEET).Range("A" & bmf_adjustment_sheet_current_row & ":" & "BN" & bmf_adjustment_sheet_current_row).NumberFormat = "@"
        ' Selection.NumberFormat = RED_THOUSAND_SEP_NUMBER_FORMAT
        Worksheets(BMF_ADJUSTMENT_WORKSHEET).Range(COL_BMF_ADJUSTMENT_SHEET_AMOUNT_IN_ACCT_BALANCE & bmf_adjustment_sheet_current_row).NumberFormat = RED_THOUSAND_SEP_NUMBER_FORMAT
        Worksheets(BMF_ADJUSTMENT_WORKSHEET).Range(COL_BMF_ADJUSTMENT_SHEET_AMOUNT_IN_FUNT & bmf_adjustment_sheet_current_row).NumberFormat = RED_THOUSAND_SEP_NUMBER_FORMAT



      End If

      ' balance sheet 2
      ' check need to copy ? see amount to adjust <> 0 ?
      debug.print bal_pcco_2
      If (CheckIfBalanceSheetAmountToAdjust2NoNeedCopy(adjustment_sheet_current_row, bmf_id, bal_pcco_2)) Then
        ' do skip
        Debug.Print "skip balance sheet 2"
      Else
        ' do copy
        bmf_adjustment_sheet_last_row = getBMFAdjustmentResultListEnd(1)
        bmf_adjustment_sheet_current_row = bmf_adjustment_sheet_last_row + 1
        temp_value = Worksheets(ADJUSTMENT_WORKSHEET).Range(COL_FINAL_BMF_ID & CStr(adjustment_sheet_current_row)).Value
        Worksheets(BMF_ADJUSTMENT_WORKSHEET).Range(COL_BMF_ADJUSTMENT_SHEET_BMF_REFERENCE_ID & CStr(bmf_adjustment_sheet_current_row)).Value = temp_value
        Worksheets(BMF_ADJUSTMENT_WORKSHEET).Range(COL_BMF_ADJUSTMENT_SHEET_REPORTING_ENTITY & CStr(bmf_adjustment_sheet_current_row)).Value = "14004"
        Worksheets(BMF_ADJUSTMENT_WORKSHEET).Range(COL_BMF_ADJUSTMENT_SHEET_OPAQUE_REPORTING_ENTITY & CStr(bmf_adjustment_sheet_current_row)).Value = "N"


        temp_value = Worksheets(ADJUSTMENT_WORKSHEET).Range(COL_BALANCE_SHEET_PCCO_2 & CStr(adjustment_sheet_current_row)).Value
        Worksheets(BMF_ADJUSTMENT_WORKSHEET).Range(COL_BMF_ADJUSTMENT_SHEET_PCCO & CStr(bmf_adjustment_sheet_current_row)).Value = temp_value

        temp_value = Worksheets(ADJUSTMENT_WORKSHEET).Range(COL_BALANCE_SHEET_AMOUNT_TO_ADJ_2 & CStr(adjustment_sheet_current_row)).Value
        Worksheets(BMF_ADJUSTMENT_WORKSHEET).Range(COL_BMF_ADJUSTMENT_SHEET_AMOUNT_IN_ACCT_BALANCE & CStr(bmf_adjustment_sheet_current_row)).Value = temp_value
        Worksheets(BMF_ADJUSTMENT_WORKSHEET).Range(COL_BMF_ADJUSTMENT_SHEET_AMOUNT_IN_FUNT & CStr(bmf_adjustment_sheet_current_row)).Value = temp_value

        temp_value = Worksheets(ADJUSTMENT_WORKSHEET).Range(COL_BALANCE_SHEET_NA_2 & CStr(adjustment_sheet_current_row)).Value
        Worksheets(BMF_ADJUSTMENT_WORKSHEET).Range(COL_BMF_ADJUSTMENT_SHEET_LOCAL_OPERATIONAL_ACCOUNT & CStr(bmf_adjustment_sheet_current_row)).Value = temp_value & " " & "15130"
        
        Worksheets(BMF_ADJUSTMENT_WORKSHEET).Range("A" & bmf_adjustment_sheet_current_row & ":" & "BN" & bmf_adjustment_sheet_current_row).NumberFormat = "@"
        Worksheets(BMF_ADJUSTMENT_WORKSHEET).Range(COL_BMF_ADJUSTMENT_SHEET_AMOUNT_IN_ACCT_BALANCE & bmf_adjustment_sheet_current_row).NumberFormat = RED_THOUSAND_SEP_NUMBER_FORMAT
        Worksheets(BMF_ADJUSTMENT_WORKSHEET).Range(COL_BMF_ADJUSTMENT_SHEET_AMOUNT_IN_FUNT & bmf_adjustment_sheet_current_row).NumberFormat = RED_THOUSAND_SEP_NUMBER_FORMAT

      End If

      ' off-balance sheet 1
      ' check need to copy ? see amount to adjust <> 0 ?
      If (CheckIfOffBalanceSheetAmountToAdjust1NoNeedCopy(adjustment_sheet_current_row, bmf_id, off_bal_pcco_1)) Then
        ' do skip
        Debug.Print "skip off-balance sheet 1"
      Else
        ' do copy
        bmf_adjustment_sheet_last_row = getBMFAdjustmentResultListEnd(1)
        bmf_adjustment_sheet_current_row = bmf_adjustment_sheet_last_row + 1
        temp_value = Worksheets(ADJUSTMENT_WORKSHEET).Range(COL_FINAL_BMF_ID & CStr(adjustment_sheet_current_row)).Value
        Worksheets(BMF_ADJUSTMENT_WORKSHEET).Range(COL_BMF_ADJUSTMENT_SHEET_BMF_REFERENCE_ID & CStr(bmf_adjustment_sheet_current_row)).Value = temp_value
        Worksheets(BMF_ADJUSTMENT_WORKSHEET).Range(COL_BMF_ADJUSTMENT_SHEET_REPORTING_ENTITY & CStr(bmf_adjustment_sheet_current_row)).Value = "14004"
        Worksheets(BMF_ADJUSTMENT_WORKSHEET).Range(COL_BMF_ADJUSTMENT_SHEET_OPAQUE_REPORTING_ENTITY & CStr(bmf_adjustment_sheet_current_row)).Value = "N"


        temp_value = Worksheets(ADJUSTMENT_WORKSHEET).Range(COL_OFF_BALANCE_SHEET_PCCO_1 & CStr(adjustment_sheet_current_row)).Value
        Worksheets(BMF_ADJUSTMENT_WORKSHEET).Range(COL_BMF_ADJUSTMENT_SHEET_PCCO & CStr(bmf_adjustment_sheet_current_row)).Value = temp_value

        temp_value = Worksheets(ADJUSTMENT_WORKSHEET).Range(COL_OFF_BALANCE_SHEET_AMOUNT_TO_ADJ_1 & CStr(adjustment_sheet_current_row)).Value
        Worksheets(BMF_ADJUSTMENT_WORKSHEET).Range(COL_BMF_ADJUSTMENT_SHEET_AMOUNT_IN_ACCT_BALANCE & CStr(bmf_adjustment_sheet_current_row)).Value = temp_value
        Worksheets(BMF_ADJUSTMENT_WORKSHEET).Range(COL_BMF_ADJUSTMENT_SHEET_AMOUNT_IN_FUNT & CStr(bmf_adjustment_sheet_current_row)).Value = temp_value

        temp_value = Worksheets(ADJUSTMENT_WORKSHEET).Range(COL_OFF_BALANCE_SHEET_NA_1 & CStr(adjustment_sheet_current_row)).Value
        Worksheets(BMF_ADJUSTMENT_WORKSHEET).Range(COL_BMF_ADJUSTMENT_SHEET_LOCAL_OPERATIONAL_ACCOUNT & CStr(bmf_adjustment_sheet_current_row)).Value = temp_value & " " & "15130"

        Worksheets(BMF_ADJUSTMENT_WORKSHEET).Range("A" & bmf_adjustment_sheet_current_row & ":" & "BN" & bmf_adjustment_sheet_current_row).NumberFormat = "@"
        Worksheets(BMF_ADJUSTMENT_WORKSHEET).Range(COL_BMF_ADJUSTMENT_SHEET_AMOUNT_IN_ACCT_BALANCE & bmf_adjustment_sheet_current_row).NumberFormat = RED_THOUSAND_SEP_NUMBER_FORMAT
        Worksheets(BMF_ADJUSTMENT_WORKSHEET).Range(COL_BMF_ADJUSTMENT_SHEET_AMOUNT_IN_FUNT & bmf_adjustment_sheet_current_row).NumberFormat = RED_THOUSAND_SEP_NUMBER_FORMAT

      End If

      ' off-balance sheet 2
      ' check need to copy ? see amount to adjust <> 0 ?
      If (CheckIfOffBalanceSheetAmountToAdjust2NoNeedCopy(adjustment_sheet_current_row, bmf_id, off_bal_pcco_2)) Then
        ' do skip
        Debug.Print "skip off-balance sheet 2"
      Else
        ' do copy
        bmf_adjustment_sheet_last_row = getBMFAdjustmentResultListEnd(1)
        bmf_adjustment_sheet_current_row = bmf_adjustment_sheet_last_row + 1
        temp_value = Worksheets(ADJUSTMENT_WORKSHEET).Range(COL_FINAL_BMF_ID & CStr(adjustment_sheet_current_row)).Value
        Worksheets(BMF_ADJUSTMENT_WORKSHEET).Range(COL_BMF_ADJUSTMENT_SHEET_BMF_REFERENCE_ID & CStr(bmf_adjustment_sheet_current_row)).Value = temp_value
        Worksheets(BMF_ADJUSTMENT_WORKSHEET).Range(COL_BMF_ADJUSTMENT_SHEET_REPORTING_ENTITY & CStr(bmf_adjustment_sheet_current_row)).Value = "14004"
        Worksheets(BMF_ADJUSTMENT_WORKSHEET).Range(COL_BMF_ADJUSTMENT_SHEET_OPAQUE_REPORTING_ENTITY & CStr(bmf_adjustment_sheet_current_row)).Value = "N"

        temp_value = Worksheets(ADJUSTMENT_WORKSHEET).Range(COL_OFF_BALANCE_SHEET_PCCO_2 & CStr(adjustment_sheet_current_row)).Value
        Worksheets(BMF_ADJUSTMENT_WORKSHEET).Range(COL_BMF_ADJUSTMENT_SHEET_PCCO & CStr(bmf_adjustment_sheet_current_row)).Value = temp_value

        temp_value = Worksheets(ADJUSTMENT_WORKSHEET).Range(COL_OFF_BALANCE_SHEET_AMOUNT_TO_ADJ_2 & CStr(adjustment_sheet_current_row)).Value
        Worksheets(BMF_ADJUSTMENT_WORKSHEET).Range(COL_BMF_ADJUSTMENT_SHEET_AMOUNT_IN_ACCT_BALANCE & CStr(bmf_adjustment_sheet_current_row)).Value = temp_value
        Worksheets(BMF_ADJUSTMENT_WORKSHEET).Range(COL_BMF_ADJUSTMENT_SHEET_AMOUNT_IN_FUNT & CStr(bmf_adjustment_sheet_current_row)).Value = temp_value

        temp_value = Worksheets(ADJUSTMENT_WORKSHEET).Range(COL_OFF_BALANCE_SHEET_NA_2 & CStr(adjustment_sheet_current_row)).Value
        Worksheets(BMF_ADJUSTMENT_WORKSHEET).Range(COL_BMF_ADJUSTMENT_SHEET_LOCAL_OPERATIONAL_ACCOUNT & CStr(bmf_adjustment_sheet_current_row)).Value = temp_value & " " & "15130"

        Worksheets(BMF_ADJUSTMENT_WORKSHEET).Range("A" & bmf_adjustment_sheet_current_row & ":" & "BN" & bmf_adjustment_sheet_current_row).NumberFormat = "@"
        Worksheets(BMF_ADJUSTMENT_WORKSHEET).Range(COL_BMF_ADJUSTMENT_SHEET_AMOUNT_IN_ACCT_BALANCE & bmf_adjustment_sheet_current_row).NumberFormat = RED_THOUSAND_SEP_NUMBER_FORMAT
        Worksheets(BMF_ADJUSTMENT_WORKSHEET).Range(COL_BMF_ADJUSTMENT_SHEET_AMOUNT_IN_FUNT & bmf_adjustment_sheet_current_row).NumberFormat = RED_THOUSAND_SEP_NUMBER_FORMAT

      End If

    Else
      Debug.Print adjustment_sheet_current_row & " skipping copy as bmfid is empty"
    End If
 
    
  Next adjustment_sheet_current_row

Done:
  Exit Sub

eh:
  Debug.Print "helloworld:Error: " & Err.Description

End Sub

