Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-19-2018, 09:25 PM
kevinbradley57 kevinbradley57 is offline Copy worksheet with current date as part of variable name Windows 7 64bit Copy worksheet with current date as part of variable name Office 2010 64bit
Advanced Beginner
Copy worksheet with current date as part of variable name
 
Join Date: Jul 2017
Posts: 88
kevinbradley57 is on a distinguished road
Default Copy worksheet with current date as part of variable name


I have an Excel source worksheet generated daily with filename SearchResultsDailymm.dd.yy where mm.dd.yy is the current date. I need code that will copy Columns A2:J of the source worksheet into Columns A2:J of a template worksheet with filename Daily Plan Status mm.dd.yy. The code would be housed in the target file.

Thank you.

Last edited by kevinbradley57; 04-19-2018 at 09:25 PM. Reason: Fixed typo
Reply With Quote
  #2  
Old 04-20-2018, 12:33 PM
NoSparks NoSparks is offline Copy worksheet with current date as part of variable name Windows 7 64bit Copy worksheet with current date as part of variable name Office 2010 64bit
Excel Hobbyist
 
Join Date: Nov 2013
Location: British Columbia, Canada
Posts: 842
NoSparks is a glorious beacon of lightNoSparks is a glorious beacon of lightNoSparks is a glorious beacon of lightNoSparks is a glorious beacon of lightNoSparks is a glorious beacon of light
Default

Care to make things simpler for anyone willing to assist by posting a couple of workbooks indicative of what you'd be working with, private/personal data removed of course.
Reply With Quote
  #3  
Old 04-20-2018, 04:07 PM
kevinbradley57 kevinbradley57 is offline Copy worksheet with current date as part of variable name Windows 7 64bit Copy worksheet with current date as part of variable name Office 2010 64bit
Advanced Beginner
Copy worksheet with current date as part of variable name
 
Join Date: Jul 2017
Posts: 88
kevinbradley57 is on a distinguished road
Default NoSparks - Here are the files

In addition to copying the data from the source file to the template, I need to fill any blank cells in column E with the value in column F of the same row. It works when I run it as a separate macro, but not when I embed it into the main macro.
Attached Files
File Type: xlsm Daily Plan Status 4.21.18.xlsm (37.3 KB, 11 views)
File Type: xls SearchResultsDaily 4.21.18.xls (30.5 KB, 11 views)
Reply With Quote
  #4  
Old 04-21-2018, 09:04 AM
NoSparks NoSparks is offline Copy worksheet with current date as part of variable name Windows 7 64bit Copy worksheet with current date as part of variable name Office 2010 64bit
Excel Hobbyist
 
Join Date: Nov 2013
Location: British Columbia, Canada
Posts: 842
NoSparks is a glorious beacon of lightNoSparks is a glorious beacon of lightNoSparks is a glorious beacon of lightNoSparks is a glorious beacon of lightNoSparks is a glorious beacon of light
Default

This of any help?
You could apply the required "adjustments" after this.
Code:
Sub GetPlanStatus()
        
    Dim wb As Workbook, src As Workbook
    Dim sht As Worksheet, cel As Range
    
Set sht = ThisWorkbook.ActiveSheet
'remove existing data
With sht.UsedRange.Offset(1)
    .Borders.LineStyle = xlNone
    .ClearContents
End With
'see if source is open
For Each wb In Application.Workbooks
    If wb.Name = "SearchResultsDaily " & Format(Date, "m.dd.yy") & ".xls" Then
        Set src = wb
        Exit For
    End If
Next wb
'if yes copy data
If Not src Is Nothing Then
    src.Sheets(1).UsedRange.Offset(1).Copy
'if no display message and quit
Else
    MsgBox "Workbook   " & Chr(34) & "SearchResultsDaily " & _
            Format(Date, "m.dd.yy") & ".xls" & Chr(34) & "   is not open."
    Exit Sub
End If
'paste the copied data
With sht
    .Cells(2, 1).PasteSpecial (xlPasteValues)
    'name sheet
    .Name = Left(src.Name, Len(src.Name) - 4)
    ' E from F if blank
    For Each cel In Intersect(.Columns("E"), .UsedRange)
        If cel.Value = "" Then cel.Value = cel.Offset(, 1).Value
    Next cel
    'position the cursor
    .Cells(1).Select
End With
'stop the marching ants
Application.CutCopyMode = False

End Sub
Reply With Quote
  #5  
Old 04-21-2018, 07:46 PM
kevinbradley57 kevinbradley57 is offline Copy worksheet with current date as part of variable name Windows 7 64bit Copy worksheet with current date as part of variable name Office 2010 64bit
Advanced Beginner
Copy worksheet with current date as part of variable name
 
Join Date: Jul 2017
Posts: 88
kevinbradley57 is on a distinguished road
Default

NoSparks -- That works great! Can you add code that will resort the spreadsheet by column E?
Reply With Quote
  #6  
Old 04-22-2018, 08:04 AM
NoSparks NoSparks is offline Copy worksheet with current date as part of variable name Windows 7 64bit Copy worksheet with current date as part of variable name Office 2010 64bit
Excel Hobbyist
 
Join Date: Nov 2013
Location: British Columbia, Canada
Posts: 842
NoSparks is a glorious beacon of lightNoSparks is a glorious beacon of lightNoSparks is a glorious beacon of lightNoSparks is a glorious beacon of lightNoSparks is a glorious beacon of light
Default

Sure...
Don't know if you want ascending or descending but you can easily alter that.
Change the bottom part of the code where the cursor gets positioned.
Code:
    'position the cursor for sorting
    .Cells(2, 5).Select
    'determine last row
    lr = .Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
    
    With .Sort
        .SortFields.Clear
        .SortFields.Add Key:=Range("E2"), SortOn:=xlSortOnValues, Order:=xlAscending, _
                             DataOption:=xlSortTextAsNumbers
        .SetRange Range("A2:J" & lr)
        .Header = xlNo
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
End With
'stop the marching ants
Application.CutCopyMode = False

End Sub
You'll also need to declare lr as long. Do it at the top with the other Dim statements.
Reply With Quote
  #7  
Old 04-24-2018, 11:18 AM
kevinbradley57 kevinbradley57 is offline Copy worksheet with current date as part of variable name Windows 7 64bit Copy worksheet with current date as part of variable name Office 2010 64bit
Advanced Beginner
Copy worksheet with current date as part of variable name
 
Join Date: Jul 2017
Posts: 88
kevinbradley57 is on a distinguished road
Default

Awesome. Thank you, NoSparks.
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Setting a Worksheet Name as a Variable Help rod147 Excel Programming 3 11-25-2016 08:50 AM
Copy worksheet with current date as part of variable name Date picker content control to always show current date. lucky16 Word VBA 2 07-01-2016 01:14 PM
Variable to rename a tab in a worksheet via VBA Chayes Excel Programming 5 08-07-2012 02:03 AM
Copy worksheet with current date as part of variable name Meaning of current date vs status date when saving baselines ketanco Project 1 02-08-2012 02:20 PM
Copy worksheet with current date as part of variable name How to call current PC date and/or current PC year KIM SOLIS Excel 2 11-04-2011 06:09 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:05 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft