fabianj
03-28-2016, 03:29 AM
I have written a program but there is a problem in that for which i need some immediate help and advise possible.
I have pasted the code below:
Problem: column E2 should be the product of D2-C2 but though it looks to be a simplest program the referencing thing not happening for successive row range.
Please help.
Option Explicit
Sub main()
Dim val As Double
Dim Firstrow As Integer
Dim Lastrow As Integer
Dim totscore1 As Integer
Dim i As Integer, j As Integer
Sheets("sheet1").Select
Range("D2").Select
Firstrow = ActiveCell.row
Selection.End(xlDown).Select
Lastrow = ActiveCell.row
totscore1 = Lastrow - Firstrow
Range("E2").Select
For i = 0 To totscore1
val = Cells(2, 3).Value - Cells(2, 4).Value
ActiveCell.Value = val
ActiveCell.Offset(1, 0).Select
Next i
End Sub
I get the same value -75 printed throughout.
Regards
Fabian J
[/B][/FONT]
I have pasted the code below:
Problem: column E2 should be the product of D2-C2 but though it looks to be a simplest program the referencing thing not happening for successive row range.
Please help.
Option Explicit
Sub main()
Dim val As Double
Dim Firstrow As Integer
Dim Lastrow As Integer
Dim totscore1 As Integer
Dim i As Integer, j As Integer
Sheets("sheet1").Select
Range("D2").Select
Firstrow = ActiveCell.row
Selection.End(xlDown).Select
Lastrow = ActiveCell.row
totscore1 = Lastrow - Firstrow
Range("E2").Select
For i = 0 To totscore1
val = Cells(2, 3).Value - Cells(2, 4).Value
ActiveCell.Value = val
ActiveCell.Offset(1, 0).Select
Next i
End Sub
I get the same value -75 printed throughout.
Regards
Fabian J
[/B][/FONT]