search rows for newest date, transfer to sheet w same date

littleme

Board Regular
Joined
Nov 15, 2004
Messages
156
Im sorry for being such a pain....

Posted a rather complicated question earlier. Realised was very vague. Narrowed it down.

Wondering if there is a way to:

Search column D for the most recent date, take values from column A, B, C, D in the rows that have that date and transfer to the sheet with the same date. If it possible to do without a button, but when a value changes in column D?

If there is not sheet with the correct date, is there a way to inform the user with a message box?

Grateful for any help.
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Hi littleme,

The answer you your questions is "yes", it can be done. But in order to provide you with some code you will need to provide some more information:

1. By "sheet with the same date" do you mean that the sheet's tab name is a date? If so, how is it formatted? (e.g., "24-May-07"?)

2. You mentioned triggering the code by a value changing in column D. Is the column D value changed because it was manually edited? Or is it changed due to being calculated by a formula that is now yielding a different value because one of its dependencies changed?

3. Where do you want the values placed on the destination sheet? In the next available (empty) row? Or perhaps overwrite the values currently in the second row?

Damon
 
Upvote 0
Goodness! What a quick reply! Thank you =)

Since the post, found this link:
http://www.rondebruin.nl/copy5.htm#AutoFilter

Have managed to combine codefrom that link. Sure I could delete somestuff. But it does ALMOST what I want. HOWEVER,...see below

Sub Copy_With_AdvancedFilter_To_Workbooks_New()
Dim CalcMode As Long
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim WSNew As Worksheet
Dim rng As Range
Dim cell As Range
Dim Lrow As Long
Dim foldername As String
Dim MyPath As String
Dim FieldNum As Integer

'Name of the sheet with your data
Set ws1 = Sheets("Sheet1") '<<< Change

'Set filter range : A1 is the top left cell of your filter range and
'the header of the first column, D is the last column in the filter range
Set rng = ws1.Range("A1:D" & Rows.Count)

'Set Field number of the filter column
'This example filters on the first field in the range(change the field if needed)
'In this case the range starts in A so Field:=1 is column A, 2 = column B, ......
FieldNum = 1

With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With

' Add worksheet to copy/Paste the unique list
Set ws2 = Worksheets.Add

'Fill in the path\folder where you want the new folder with the files
'you can use also this "C:\Users\Ron\test"
MyPath = "H:\Nina"

'Add a slash at the end if the user forget it
If Right(MyPath, 1) <> "\" Then
MyPath = MyPath & "\"
End If

'Create folder for the new files
foldername = MyPath & Format(Now, "yyyy-mm-dd") & "\"
MkDir foldername

'Add new workbook with one sheet
Set WSNew = Workbooks.Add(XlWBATemplate.xlWBATWorksheet).Worksheets(1)
WSNew.Name = "Netherlands"

'Firstly, remove the AutoFilter
ws1.AutoFilterMode = False

'Filter the range
rng.AutoFilter Field:=1, Criteria1:="=Netherlands"

'Copy the visible data and use PasteSpecial to paste to the new worksheet
ws1.AutoFilter.Range.Copy
With WSNew.Range("A1")
' Paste:=8 will copy the columnwidth in Excel 2000 and higher
.PasteSpecial Paste:=8
.PasteSpecial xlPasteValues
.PasteSpecial xlPasteFormats
Application.CutCopyMode = False
.Select
End With

'Save the file in the newfolder and close it
WSNew.Parent.SaveAs foldername & " Netherlands = ", ws1.Parent.FileFormat
WSNew.Parent.Close False

'Close AutoFilter
ws1.AutoFilterMode = False


MsgBox "Look in " & foldername & " for the files"

ws1.AutoFilterMode = False

'Delete the ws2 sheet
On Error Resume Next
Application.DisplayAlerts = False
ws2 = Worksheets.Delete
Application.DisplayAlerts = True
On Error GoTo 0


MsgBox "Look in " & foldername & " for the files"

With Application
.ScreenUpdating = True
.Calculation = CalcMode
End With
End Sub

HOWEVER are some problems i dont know how to deal with:
1. How do I delete the temporary ws2?
2. How do I open a template called eg RESULT and paste filter result beginning at A3?
3. How do i set so that when the filter is done, it only copies and paste vaues in colums A, G and H into columns A, B C in Result-sheet?

Realise totally new post but.. maybe you can help?
 
Upvote 0
Hi again littleme,

The code you posted does not do anything like what I think you described you wanted. It definitely doesn't run automatically when cells in col D change. The problem you described should not require more than about 20 lines of code. But again, I can't provide more help without the answers to those questions.

Damon
 
Upvote 0
Sorry... realise the code doestn do what i asked in the original post. It will serve my purposes though goin about it in a different (smarter?) way. As I havent managed to get it to do exactly what I need, be glad to get your ideas for alternative:

To answer your questions:
1. The sheets tab is a date. formatted "PM 2007-12-05"

2. Column D will be manually edited.

3. The values should find sheet with the same name and then place themselves on the next empty row.

Thank you again for taking the time to help
 
Upvote 0

Forum statistics

Threads
1,214,406
Messages
6,119,330
Members
448,888
Latest member
Arle8907

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top