find-out-if-a-cell-is-within-a-range

Nick's picture
find-out-if-a-cell-is-within-a-range


Screen shot of VBA Tips - Find Out If A Cell Is Within A Range

Follow this link for whole Excel Tip on how to Find Out If A Cell Is Within A Range

Macros

Sir,
I have entered a date 01/05/2009 (1st may of 2009)in "a1" cell and entered another date 01/08/2010 (1st august of 2010) I have to write a macro to copy a formula "=Date(year(a1),month(a1)+1,1)" from a2 to down in the same column i.e,,column A ( one month increment to previous cell). I wrote the following code. but it does not work

Public Sub mydate()
If ActiveCell.Cells(2, 1) = Cells(1, 2) Then
ActiveCell.Vaue = ""
Else
ActiveCell.FormulaR1C1 = "=DATE(YEAR(Cells(2,1)),MONTH(Cells(2,1))+1,1)"
ActiveCell.Offset(1, 0).Select
End If
End Sub

'Do While ActiveCell.Cells(2, 1) = ActiveCell.Cells(1, 2)
'ActiveCell.FormulaR1C1 = "=DATE(YEAR(Cells(2,1)),MONTH(Cells(2,1))+1,1)"
'Loop

'Do
'ActiveCell.FormulaR1C1 = "=IF(R[-1]C)=(R[-1]C[1])),"",DATE(YEAR(R[-1]C),MONTH(R[-1]C)+1,1))"
'ActiveCell.Offset(1, 0).Select
'Loop Until IsEmpty(ActiveCell.Offset(1, 0))

'Do While ActiveCell.Cells(2, 1) = ActiveCell.Cells(1, 2)
'ActiveCell.FormulaR1C1 = "=DATE(YEAR(R[-1]C),MONTH(R[-1]C)+1,1)"
'ActiveCell.Offset(1, 0).Select
'Loop

'If ActiveCell.Value = Cells(1, 2) Then End
'Else
'ActiveCell.FormulaR1C1 = "=DATE(YEAR(R[-1]C),MONTH(R[-1]C)+1,1)"

'Do
' ActiveCell.FormulaR1C1 = "=DATE(YEAR(R[-1]C),MONTH(R[-1]C)+1,1)"
' ActiveCell.Offset(1, 0).Select
'Loop Until ActiveCell.Offset(1, 0).Value = Cells(1, 2)
'End Sub

'Sub Loop1()
' This loop runs until there is nothing in the next column
'Do
'ActiveCell.FormulaR1C1 = "=Average(RC[-1],RC[-2])"
'ActiveCell.Offset(1, 0).Select
'Loop Until IsEmpty(ActiveCell.Offset(0, 1))
'End Sub

Kindly held in this issue.

deekshituluchs@gmail.com