Sargad_Strut
New Member
- Joined
- Mar 28, 2014
- Messages
- 44
Hi all,
I have a rather simple code where I want to split a row in two (say a bill). Some of the cells will contain the same information (e.g. date), which is just copied from the row I am splitting. When the row is split, I want some cells in the new row to be the residuals of the total amount (as in the original row) minus whatever value I descide to assign to that same row after running the code. E.g. the bill is for $500, I press "Split" and a row is inserted below. I enter $300 in the original row and the one below now shows $200. This is what I have:
At first I thught it worked perfectly, but I later found out that this was only the case for integers; as soon as there are decimals the code crashes. How can I solve this? The three cells you see in the code are formatted as accounting. Or maybe there's a better way of doing this..
Best regards,
Tobias
I have a rather simple code where I want to split a row in two (say a bill). Some of the cells will contain the same information (e.g. date), which is just copied from the row I am splitting. When the row is split, I want some cells in the new row to be the residuals of the total amount (as in the original row) minus whatever value I descide to assign to that same row after running the code. E.g. the bill is for $500, I press "Split" and a row is inserted below. I enter $300 in the original row and the one below now shows $200. This is what I have:
Code:
Sub delaRad()
rad = ActiveCell.Row
summa = Range("G" & rad).Value
moms = Range("H" & rad).Value
tot = Range("I" & rad).Value
Rows(rad + 1 & ":" & rad + 1).Select
Selection.Insert Shift:=xlDown
Range("B" & rad & ":F" & rad).Select
Selection.Copy
Range("B" & rad + 1).Select
ActiveSheet.Paste
Range("G" & rad + 1) = "=" & summa & "-R[-1]C[0]"
Range("H" & rad + 1) = "=" & moms & "-R[-1]C[0]"
Range("I" & rad + 1) = "=" & tot & "-R[-1]C[0]"
Application.CutCopyMode = False
Range("B" & rad + 1).Select
End Sub
At first I thught it worked perfectly, but I later found out that this was only the case for integers; as soon as there are decimals the code crashes. How can I solve this? The three cells you see in the code are formatted as accounting. Or maybe there's a better way of doing this..
Best regards,
Tobias