(VBA) Extracting data from a newly created sheet (dates/multiple tabs)

Garrix

New Member
Joined
Aug 13, 2014
Messages
28
I'm not sure if I'm on the right track or if I started off entirely in the wrong place. I have the below, which I am using to create a new workbook. After that workbook is created, I would like to use those same variables (the dstart & dend) to define a range, which will be copied out of each of 3 separately named worksheets (the range will be the same, the worksheets will not be), and then pasted into the newly created workbook.

As a quick note I got part of this (the error handling part, and some optimization) from stackoverflow... and when I went into the second part of what I needed (the extraction part) I found out there is generally a much higher base skill ceiling there; I was a bit out of my depth.

Code:
Sub CreateNewWorkbookAsName()
   Dim CurrentWorkbook As String
   Dim CurrentFormat As Long
   Dim dStart As Date
   Dim dEnd As Date
    
    On Error GoTo bm_SlapWrist
    dStart = Application.InputBox("Please enter start date. (dd-mm-yyyy)")
    dEnd = Application.InputBox("Please enter end date. (dd-mm-yyyy)")
    Filename = Format(dStart, "dd-mm-yyyy") + " to " + Format(dEnd, "dd-mm-yyyy") + ".xlsm"
 
    With ThisWorkbook
     CurrentWorkbook = .FullName
     CurrentFormat = .FileFormat
     .SaveAs Filename:=Format(dStart, "dd-mm-yyyy") & " to " & Format(dEnd, "dd-mm-yyyy"), _
            FileFormat:=CurrentFormat
    End With
   '  Call Macro2(ThisWorkbook.Name) (this part was supposed to point to the extraction macro)
    Exit Sub


bm_SlapWrist:
    If Err.Number = 13 Then  'bad date: Type mismatch
        MsgBox "Try to get it right this time.", vbCritical, Title:="Bad User!"
        Err.Clear
        Resume
    End If


End Sub
 
Last edited:

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)

Forum statistics

Threads
1,215,214
Messages
6,123,666
Members
449,114
Latest member
aides

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