Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Have a tricky one i think... at least for me.... I enjoy the challenge
of excel and vba but never know how to start things off... Here is what I would like in a perfect world: A macro that is triggered when workbook "LIST" is saved. First message box. Do you want to transfer? If no, just save. If yes THEN..... Open new workbook based on template TRANSFER. Search column H in LIST for rows with most recent date. Extract information froms those rows, but only info found i columns A, G and H and place in new workbook on first available rows into columns A, B and C. Does this make sense? Is it really hard? Can anyone help me? Would really appreciate any scrap of help... |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Place this in the ThisWorkbook module of the workbook being saved.
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean) Dim newWb As Workbook, origWb As Workbook Dim cl As Range, sRange As Range Dim BotRow As Long, aRow As Long Dim rDate As Date If MsgBox("Do you want to transfer?", vbQuestion + vbYesNo) = vbYes Then BotRow = ThisWorkbook.ActiveSheet.Range("H65536").End(xlUp) .Row Set newWb = Workbooks.Add(Template:="C:\TemplateFile.xlt") Set sRange = ThisWorkbook.ActiveSheet.Range("H2:H" & BotRow) rDate = WorksheetFunction.Max(sRange) For Each cl In sRange If cl.Value = rDate Then r = cl.Row ThisWorkbook.ActiveSheet.Range("A" & r & ",G" & r & ",H" & r).Copy newWb.ActiveSheet.Range("A65536").End(xlUp).Offset (1, 0).PasteSpecial xlPasteAll Application.CutCopyMode = False End If Next End If End Sub Please note that this is not tested thoroughly and contains no error handling. This could be streamline da little further, but this gets the job done. You may need to make a few tweaks here and there. And you'll need to plug in the location of your template file. HTH -Jeff- littleme wrote: Have a tricky one i think... at least for me.... I enjoy the challenge of excel and vba but never know how to start things off... Here is what I would like in a perfect world: A macro that is triggered when workbook "LIST" is saved. First message box. Do you want to transfer? If no, just save. If yes THEN..... Open new workbook based on template TRANSFER. Search column H in LIST for rows with most recent date. Extract information froms those rows, but only info found i columns A, G and H and place in new workbook on first available rows into columns A, B and C. Does this make sense? Is it really hard? Can anyone help me? Would really appreciate any scrap of help... |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Just realised there are a couple variables in there not being used.
You can remove the origWb and aRow variables. JW wrote: Place this in the ThisWorkbook module of the workbook being saved. Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean) Dim newWb As Workbook, origWb As Workbook Dim cl As Range, sRange As Range Dim BotRow As Long, aRow As Long Dim rDate As Date If MsgBox("Do you want to transfer?", vbQuestion + vbYesNo) = vbYes Then BotRow = ThisWorkbook.ActiveSheet.Range("H65536").End(xlUp) .Row Set newWb = Workbooks.Add(Template:="C:\TemplateFile.xlt") Set sRange = ThisWorkbook.ActiveSheet.Range("H2:H" & BotRow) rDate = WorksheetFunction.Max(sRange) For Each cl In sRange If cl.Value = rDate Then r = cl.Row ThisWorkbook.ActiveSheet.Range("A" & r & ",G" & r & ",H" & r).Copy newWb.ActiveSheet.Range("A65536").End(xlUp).Offset (1, 0).PasteSpecial xlPasteAll Application.CutCopyMode = False End If Next End If End Sub Please note that this is not tested thoroughly and contains no error handling. This could be streamline da little further, but this gets the job done. You may need to make a few tweaks here and there. And you'll need to plug in the location of your template file. HTH -Jeff- littleme wrote: Have a tricky one i think... at least for me.... I enjoy the challenge of excel and vba but never know how to start things off... Here is what I would like in a perfect world: A macro that is triggered when workbook "LIST" is saved. First message box. Do you want to transfer? If no, just save. If yes THEN..... Open new workbook based on template TRANSFER. Search column H in LIST for rows with most recent date. Extract information froms those rows, but only info found i columns A, G and H and place in new workbook on first available rows into columns A, B and C. Does this make sense? Is it really hard? Can anyone help me? Would really appreciate any scrap of help... |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
in Excel, dates appear as crosshatched lines, especially if copy,. | Excel Discussion (Misc queries) | |||
Find a "date" in a column of dates in Excel 2000 | Excel Worksheet Functions | |||
Trying to create repeating dates and then sort column by date | Excel Worksheet Functions | |||
How to create chart with 1 column and 3 lines | Charts and Charting in Excel |