Mitchys
09-24-2006, 06:13 PM
G'day,
The following function is to be used to change values from a trial balance prior to entry into another sheet. The trial balance displays all credit items as negative, and all debit items as positive. The sheet this is going into works differenty. Income, for example, should only have a negative number if the number is a debit balance - such as cost of goods sold. An expenditure item should be positive, unless is is something like a reimbursement. Etc., etc.
The function below takes two arguments - CellRef and TBAmount. The cell containing the CellRef is made up of either a 5 or 6 digit number (always). The first number in the five-digit number contains a column reference (therefore, the first two numbers in the six-digit number contains a column reference for column references greater than 9). The last four digits in both of these numbers contain the row reference.
Now, before going any further, I have no control over the CellRef number or the sheet to which the TBAmount is going into. All I can do is manipulate the data between the trial balance and the financial statement input.
Also, I have successfully written code that uses the CellRef to export the TBAmount into the financial statement input. All I need now is to change the trial balance figure to a negative or positive in order for it to correctly display in the financial statement spreadsheet.
Now for my problem. I am attempting to write a function that will give me the row number, and based on that row number, change the TBAmount to either a positive or negative. The problem I am having is that the following line of code returns two digits for CellRef instead of either five or six:If Len(CellRef) = 6 ThenTo prove this, I used the following line in the function:MsgBox "Length of CellRef = " & Len(CellRef)The message box comes up as "Length of CellRef = 2". Is this telling me the cell reference = 2? (i.e. if the cell for the function input is, say, "L4" - i.e. giving me the length of the cell reference rather than the cell value?) If so, how do I get the length of the value IN cell "L4"?
OK, so here is my entire function:Public Function ADJTB(CellRef As Integer, TBAmount As Double)
Dim RowNum As Integer
Dim FRAMME_No As Double
If Len(CellRef) = 5 Then
RowNum = Mid(CellRef, 2, 4)
End If
If Len(CellRef) = 6 Then
RowNum = Mid(CellRef, 3, 4)
End If
'1455 to 2077
If RowNum > 1454 Then
If TBAmount < 0 Then
FRAMME_No = TBAmount * -1
Else
FRAMME_No = TBAmount * -1
End If
End If
'1284 to 1454
If RowNum > 1283 Then
If TBAmount < 0 Then
FRAMME_No = TBAmount
Else
FRAMME_No = TBAmount
End If
End If
'1200 to 1283
If RowNum > 1999 Then
If TBAmount < 0 Then
FRAMME_No = TBAmount * -1
Else
FRAMME_No = TBAmount * -1
End If
End If
'571 to 1200
If RowNum > 570 Then
If TBAmount < 0 Then
FRAMME_No = TBAmount
Else
FRAMME_No = TBAmount
End If
End If
'493 to 570
If RowNum > 492 Then
If TBAmount < 0 Then
FRAMME_No = TBAmount
Else
FRAMME_No = TBAmount
End If
End If
'456 to 492
If RowNum > 455 Then
FRAMME_No = "Check Individually"
End If
'337 to 455
If RowNum > 336 Then
If TBAmount < 0 Then
FRAMME_No = TBAmount
Else
FRAMME_No = TBAmount
End If
End If
'12 to 336
If RowNum > 11 Then
If TBAmount < 0 Then
FRAMME_No = TBAmount * -1
Else
FRAMME_No = TBAmount * -1
End If
End If
ADJTB = FRAMME_No
End FunctionAny assistance would be greatly appreciated.
Thanks,
Mitchys
The following function is to be used to change values from a trial balance prior to entry into another sheet. The trial balance displays all credit items as negative, and all debit items as positive. The sheet this is going into works differenty. Income, for example, should only have a negative number if the number is a debit balance - such as cost of goods sold. An expenditure item should be positive, unless is is something like a reimbursement. Etc., etc.
The function below takes two arguments - CellRef and TBAmount. The cell containing the CellRef is made up of either a 5 or 6 digit number (always). The first number in the five-digit number contains a column reference (therefore, the first two numbers in the six-digit number contains a column reference for column references greater than 9). The last four digits in both of these numbers contain the row reference.
Now, before going any further, I have no control over the CellRef number or the sheet to which the TBAmount is going into. All I can do is manipulate the data between the trial balance and the financial statement input.
Also, I have successfully written code that uses the CellRef to export the TBAmount into the financial statement input. All I need now is to change the trial balance figure to a negative or positive in order for it to correctly display in the financial statement spreadsheet.
Now for my problem. I am attempting to write a function that will give me the row number, and based on that row number, change the TBAmount to either a positive or negative. The problem I am having is that the following line of code returns two digits for CellRef instead of either five or six:If Len(CellRef) = 6 ThenTo prove this, I used the following line in the function:MsgBox "Length of CellRef = " & Len(CellRef)The message box comes up as "Length of CellRef = 2". Is this telling me the cell reference = 2? (i.e. if the cell for the function input is, say, "L4" - i.e. giving me the length of the cell reference rather than the cell value?) If so, how do I get the length of the value IN cell "L4"?
OK, so here is my entire function:Public Function ADJTB(CellRef As Integer, TBAmount As Double)
Dim RowNum As Integer
Dim FRAMME_No As Double
If Len(CellRef) = 5 Then
RowNum = Mid(CellRef, 2, 4)
End If
If Len(CellRef) = 6 Then
RowNum = Mid(CellRef, 3, 4)
End If
'1455 to 2077
If RowNum > 1454 Then
If TBAmount < 0 Then
FRAMME_No = TBAmount * -1
Else
FRAMME_No = TBAmount * -1
End If
End If
'1284 to 1454
If RowNum > 1283 Then
If TBAmount < 0 Then
FRAMME_No = TBAmount
Else
FRAMME_No = TBAmount
End If
End If
'1200 to 1283
If RowNum > 1999 Then
If TBAmount < 0 Then
FRAMME_No = TBAmount * -1
Else
FRAMME_No = TBAmount * -1
End If
End If
'571 to 1200
If RowNum > 570 Then
If TBAmount < 0 Then
FRAMME_No = TBAmount
Else
FRAMME_No = TBAmount
End If
End If
'493 to 570
If RowNum > 492 Then
If TBAmount < 0 Then
FRAMME_No = TBAmount
Else
FRAMME_No = TBAmount
End If
End If
'456 to 492
If RowNum > 455 Then
FRAMME_No = "Check Individually"
End If
'337 to 455
If RowNum > 336 Then
If TBAmount < 0 Then
FRAMME_No = TBAmount
Else
FRAMME_No = TBAmount
End If
End If
'12 to 336
If RowNum > 11 Then
If TBAmount < 0 Then
FRAMME_No = TBAmount * -1
Else
FRAMME_No = TBAmount * -1
End If
End If
ADJTB = FRAMME_No
End FunctionAny assistance would be greatly appreciated.
Thanks,
Mitchys