beelzebubble
Board Regular
- Joined
- Jun 11, 2009
- Messages
- 68
Hi,
I'm using excel 2003. Using the macro recorder, I was able to produce vba code to calculate the absolute difference between two values for 15 rows of data. That is, 15 data points in column A and 15 data points in column B. The absolute difference values are places in column C.
I am trying to modify the above code to make it more flexible, but without success. That is, I would like the code to work on data sets that may have different numbers of rows (i.e., without having to manually change the number of rows). Say, one data set might have 37 rows and another might have 337. Secondly, I would like the code to place the absolute difference scores in the next available column in the excel sheet, rather than specifying the column.
Thanks for your help.
I'm using excel 2003. Using the macro recorder, I was able to produce vba code to calculate the absolute difference between two values for 15 rows of data. That is, 15 data points in column A and 15 data points in column B. The absolute difference values are places in column C.
Code:
Sub test()
Range("C1").Select
ActiveCell.FormulaR1C1 = "=ABS(RC[-2]-RC[-1])"
Range("C1").Select
Selection.AutoFill Destination:=Range("C1:C15")
Range("C1:C15").Select
End Sub
I am trying to modify the above code to make it more flexible, but without success. That is, I would like the code to work on data sets that may have different numbers of rows (i.e., without having to manually change the number of rows). Say, one data set might have 37 rows and another might have 337. Secondly, I would like the code to place the absolute difference scores in the next available column in the excel sheet, rather than specifying the column.
Thanks for your help.