Using dates in macros

Z

zack

Hello, I have just started in VBA and I would like to do the following:

- go through an array and look for some entries for which the dates are
in next month
- put these entries in a new sheet

Can somebody help please?

Thanx,

Zack.
 
D

DavidC

Hi,
You probably need a routine such as this but with sheet
names and cell referneces that reflect your particular
situation:

mth = Month(Date) + 1

For a = 1 To 30

Worksheets("Sheet2").Select

If Month(Cells(a, 1)) = mth Then

With Worksheets("Sheet2")
..Range(.Cells(a, 1), .Cells(a, 5)).Copy
End With

Worksheets("sheet1").Select

ActiveSheet.Cells(a, 1).PasteSpecial

Else


End If

Next a

End Sub

Best of luck
DavidC
 
B

BrianB

This is the basic code which you will need to adapt as required :-


Code
-------------------
Sub test()
Dim NextMonth As Integer
Dim FromRow As Long
Dim ToRow As Long
'--------------------
NextMonth = Month(Date) + 1
ToRow = 1
'--
For FromRow = 1 To 1000
If Month(ActiveSheet.Cells(FromRow, 1).Value) = NextMonth Then
Worksheets("Sheet1").Cells(ToRow, 1).Value = _
ActiveSheet.Cells(FromRow, 1).Value
ToRow = ToRow + 1
End If
Next
MsgBox ("Done.")
End Sub
 
Top