Question : How to change a date value (cell value)

I like to know how to increment the date value in excel by macro, here is the requiremnt

cell value (say A1)  is "01-jan-2008"

base on this A1 value I will like to add 7 day to this value so that it will become "08-jan-2008" and then duplicate the value to A10.
logic:
1) build a button to trigger the action
2) if A1 is a date value,
          validate the date to check if the date is the correct date,
          if not , allow user to change the date value
          perform add 7 day to the value
          copy A1 to A2..A10
    else
          error message
    fi

thank you,


       

Answer : How to change a date value (cell value)

Yeah, for some reason, it doesn't like going back to TEXT. One way is to use an apostrophe prefix, which denotes TEXT....
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
Sub IncrementDate()
    If Not IsDate(Range("A1")) Then
        Range("A1") = Application.InputBox(Prompt:="Cell A1 does not contain a valid date." & _
                                                   vbCrLf & "Enter a valid date...", Type:=2)
    End If
    Range("A1") = Range("A1") + 7
    Range("A1").AutoFill Range("A1:A10"), xlFillCopy
    Dim r As Long
    For r = 1 To 10
        Cells(r, "A") = "'" & Format(Cells(r, "A"), "dd-mm-yy")
    Next
End Sub
Random Solutions  
 
programming4us programming4us