G
Gareth
I have a macro which is made up of seven macros which do almost exactly the
same thing. The only thing that differs each time is the cell that is
copied and the destination of the filtered information. A2 is copied into
D1 on sheet2 and column D is then filtered and if any data is found it is
copied to A5 on sheet1.
This process is repeated 7 times for dates in A2:G2
What I would like to do is simplify the process by not having the same code
used 7 times. Is this possible?
I have enclosed one of the macros so that you can see how it is done.
Sub Checkdate1()
If Not IsEmpty(Worksheets("Sheet1").Range("A2").Value) Then
Worksheets("Sheet2").Range("D1").Value =
Worksheets("Sheet1").Range("A2").Value
Range("B1").AutoFilter Field:=4, Criteria1:=">=6"
Set rng = ActiveSheet.AutoFilter.Range
Set rng1 = Intersect(rng, Columns(2)).SpecialCells(xlVisible)
If rng1.Count <= 1 Then
Selection.AutoFilter Field:=4
Exit Sub
End If
Set rng = rng.Offset(1, 0).Resize(rng.Rows.Count - 1, rng.Columns.Count)
Set rng = Intersect(rng, Range("C:C"))
rng.Copy Worksheets("Sheet1").Range("A5")
Selection.AutoFilter Field:=4
End If
End Sub
same thing. The only thing that differs each time is the cell that is
copied and the destination of the filtered information. A2 is copied into
D1 on sheet2 and column D is then filtered and if any data is found it is
copied to A5 on sheet1.
This process is repeated 7 times for dates in A2:G2
What I would like to do is simplify the process by not having the same code
used 7 times. Is this possible?
I have enclosed one of the macros so that you can see how it is done.
Sub Checkdate1()
If Not IsEmpty(Worksheets("Sheet1").Range("A2").Value) Then
Worksheets("Sheet2").Range("D1").Value =
Worksheets("Sheet1").Range("A2").Value
Range("B1").AutoFilter Field:=4, Criteria1:=">=6"
Set rng = ActiveSheet.AutoFilter.Range
Set rng1 = Intersect(rng, Columns(2)).SpecialCells(xlVisible)
If rng1.Count <= 1 Then
Selection.AutoFilter Field:=4
Exit Sub
End If
Set rng = rng.Offset(1, 0).Resize(rng.Rows.Count - 1, rng.Columns.Count)
Set rng = Intersect(rng, Range("C:C"))
rng.Copy Worksheets("Sheet1").Range("A5")
Selection.AutoFilter Field:=4
End If
End Sub