I’ve a worksheet where the number format is used to scale the numbers into thousands.
# ##0,_);(# ##0,);-
I’ve also a DBRW where I want the user to input some values and I need to have these numbers scaled on the way into TM1. So if I type 1 in a cell I must have a thousand in the cell. At first thought I was thinking a bit of VBA or even simpler changing the options would get this done pretty easy.
Think again….
I’ve tried changing the options to fixed decimal places to -3, this works in Excel with the TM1 add in but doesn’t when you try and do it on a DBRW.
Next attempt was a very simple piece of VBA that just multiplied the value that had just been entered by 1,000.
Code: Select all
Private Sub Worksheet_Change(ByVal Target As Range)
'check to see if we are on an input line where we need to apply multiplier to the input values
Application.EnableEvents = False
If Target.Offset(0, -Target.Column + 1) = "Mvt - Override" Then
Target.value = Target.value * 1000
End If
Application.EnableEvents = True
End Sub
My next attempt was to unpick the DBRW in the cell and use this to run a DBS in the VBA using the change event.
Code: Select all
Public cellFormula As String
Type formRef
address As String
value As String
End Type
‘sheet event macros
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'required as while the DBRW is "executing" Target.formula=Target.value
'which means I have to capture the DBRW formula before the edit is made.
cellFormula = Target.Formula
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
'check to see if we are on an input line where we need to apply multiplier to the input values
Application.EnableEvents = False
If Target.Offset(0, -Target.Column + 1) = "Mvt - Override" Then
Call InSheetMacros.AmendSend(Target)
End If
Application.EnableEvents = True
End Sub
Code: Select all
Sub AmendSend(c As Range)
'hard coded to work with a DBRW with 7 arguements inclduing the cube ref
Dim argue(7) As formRef, lastChar As Integer, ixArray As Integer, refCount As Integer
Dim ans As Variant, valueToSend As Double
Const checkChar = ","
Const firstBit = "=DBRW("
'scale the input amount
valueToSend = c.value * 1000
'establish the cell references in the formula
argue(1).address = Mid(cellFormula, Len(firstBit) + 1, InStr(Len(firstBit), cellFormula, checkChar) - Len(firstBit) - 1)
lastChar = InStr(Len(firstBit), cellFormula, checkChar)
For ixArray = 2 To 7
If ixArray = 7 Then
'special case for the last bit of the formula that doesn't have a ","
refCount = Len(cellFormula)
Else
refCount = InStr(lastChar + 1, cellFormula, checkChar)
End If
argue(ixArray).address = Mid(cellFormula, lastChar + 1, refCount - lastChar - 1)
lastChar = refCount
Next ixArray
'establish the range values
For ixArray = 1 To 7
argue(ixArray).value = ActiveSheet.Range(argue(ixArray).address)
Next ixArray
'send the value in
ans = Application.Run("DBS", valueToSend, argue(1).value, argue(2).value, argue(3).value, argue(4).value, argue(5).value, argue(6).value, argue(7).value)
End Sub
Now I know from recent experience that working with Excel/VBA events seems to be getting much harder than it used to be when TM1 is thrown into the mix. I seem to remember that in good old 845 and 714 you could do pretty much as you pleased, that could be rose coloured specs though.
Anyway to get to the point, I was just wondering is anyone has tried to do this and succeeded? I’m going to rethink my approach to this so it’s no drama, just curious if the forum thinks that the DBRW should cope with the formats being set to thousands and fixed decimal being set -3 and correctly load 1,000 even if only 1 is input a cell.
Cheers