asked on
ASKER
ASKER
ASKER
Option Explicit
Public Sub Move400Data()
Dim wksThing As Worksheet
Dim intReply As VbMsgBoxResult
Dim boolFound As Boolean
Dim colNames As New Collection
Dim vItem As Variant
Dim rngFiltered As Range
Dim rngCriteria As Range
boolFound = False
For Each wksThing In ActiveWorkbook.Worksheets
If wksThing.Name Like "*0400*" Then
colNames.Add wksThing.Name
boolFound = True
End If
Next
If boolFound Then
intReply = MsgBox("Destination worksheets found. Ok to overwrite?", vbOKCancel, "Overwrite prompt")
If intReply = vbCancel Then
Exit Sub
Else
'remove existing destination worksheets
For Each vItem In colNames
ActiveWorkbook.Worksheets(CStr(vItem)).Delete
Next
End If
End If
Set colNames = New Collection
For Each wksThing In ActiveWorkbook.Worksheets
colNames.Add wksThing.Name
Next
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.Calculation = xlCalculationManual
'create destination worksheets
For Each vItem In colNames
Set wksThing = ActiveWorkbook.Worksheets.Add
wksThing.Name = vItem & "0400"
Next
'create criteria sheet/range
Set wksThing = ActiveWorkbook.Worksheets.Add()
wksThing.Visible = xlSheetHidden
Set rngCriteria = wksThing.Range("A1")
rngCriteria.Value = "GMT"
rngCriteria.Offset(1).Formula = "=time(4,0,0)"
rngCriteria.Offset(2).Formula = "=time(16,0,0)"
Set rngCriteria = wksThing.Range(rngCriteria, rngCriteria.End(xlDown))
'move data
For Each vItem In colNames
Set wksThing = ActiveWorkbook.Worksheets(vItem)
wksThing.Range("A1").CurrentRegion.AdvancedFilter xlFilterCopy, rngCriteria, Worksheets(wksThing.Name & "0400").Range("A1")
Next
'remove criteria worksheet
rngCriteria.Worksheet.Delete
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Application.Calculation = xlCalculationAutomatic
End Sub
ASKER
ASKER
Dim rngFiltered As Range
Microsoft Excel topics include formulas, formatting, VBA macros and user-defined functions, and everything else related to the spreadsheet user interface, including error messages.
TRUSTED BY
you could build a pivot table for each sheet, showing "Date GMT" and "GMT" in the row labels and the other columns in the Values area. Then click on a 4:00 time value in the pivot table, hold down Ctrl and click on a 16:00 time value. Righ-click and select Filter > "Keep only selected items".
See attached for the above applied to the EUR sheet, in a new sheet called EUR Filtered.
cheers, teylyn