vuyyuru
08-28-2011, 11:43 PM
Hi All :hi: ,
1.
I have a VBA code which auto populate cells using two dates as the parameters, which will present in A2 and B2.. and a montly std value present in C2, these value will autopopulated to the correct months ( column D is Jan 00 and column E is FEB 00 .......... goes upto DEC 2020 etc). the code is as following..
Public Sub Test2()
Dim monthOff As Long
Dim numMonths As Long
With ActiveSheet
monthOff = DateDiff("M", DateSerial(2000, 1, 1), Range("A2"))
numMonths = DateDiff("M", Range("A2"), Range("B2")) + 1
.Range("D2").Offset(, monthOff).Resize(, numMonths).Value = .Range("C2").Value
End With
End Sub
I try to change the cell references to active cell reference insted of " A2" or "B2" or "C2" or "D2". so that i can use this code for any rows... I try to change as following but not working.. any guy can help on this VBA code .. the intial cell postion before i run the code will be the cell A1 ... thanks
Public Sub srini2()
Dim monthOff As Long
Dim numMonths As Long
With ActiveSheet
monthOff = DateDiff("M", DateSerial(2000, 1, 1), ActiveCell.Offset(1, 0).Select)
numMonths = DateDiff("M", ActiveCell.Offset(0, 0).Select, ActiveCell.Offset(0, 1).Select) + 1
.(ActiveCell.Offset(0, 2).Select).Offset(, monthOff).Resize(, numMonths).Value = .ActiveCell.Offset(0, -1).Select.Value
End With
End Sub
1.
I have a VBA code which auto populate cells using two dates as the parameters, which will present in A2 and B2.. and a montly std value present in C2, these value will autopopulated to the correct months ( column D is Jan 00 and column E is FEB 00 .......... goes upto DEC 2020 etc). the code is as following..
Public Sub Test2()
Dim monthOff As Long
Dim numMonths As Long
With ActiveSheet
monthOff = DateDiff("M", DateSerial(2000, 1, 1), Range("A2"))
numMonths = DateDiff("M", Range("A2"), Range("B2")) + 1
.Range("D2").Offset(, monthOff).Resize(, numMonths).Value = .Range("C2").Value
End With
End Sub
I try to change the cell references to active cell reference insted of " A2" or "B2" or "C2" or "D2". so that i can use this code for any rows... I try to change as following but not working.. any guy can help on this VBA code .. the intial cell postion before i run the code will be the cell A1 ... thanks
Public Sub srini2()
Dim monthOff As Long
Dim numMonths As Long
With ActiveSheet
monthOff = DateDiff("M", DateSerial(2000, 1, 1), ActiveCell.Offset(1, 0).Select)
numMonths = DateDiff("M", ActiveCell.Offset(0, 0).Select, ActiveCell.Offset(0, 1).Select) + 1
.(ActiveCell.Offset(0, 2).Select).Offset(, monthOff).Resize(, numMonths).Value = .ActiveCell.Offset(0, -1).Select.Value
End With
End Sub