+ Reply to Thread
Results 1 to 4 of 4

VBA export data to path dpends upon 1 combobox values sheets & 2 textbox date values

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    07-23-2013
    Location
    bangalore
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    143

    VBA export data to path dpends upon 1 combobox values sheets & 2 textbox date values

    Dear Sir

    I have set of user-form contains with Combox & 2 textbox and to generate report one cmd button

    I have 3 different sheet contains report of daily activities ( Dispatch,Closed,Cancel)

    If Dispatchcalls Select In Combobox1 ,Then Filter Start And End Date In Two Textboxes Then Click Cmd" Export Data To Excel" Extract Data from dispatchcalls Then Save Data Into Excel File As "Dispatchcalls".

    If Closedcalls Select In Combobox1 Then Filter Start And End Date In Two Textboxes Then Click Cmd" Export Data To Excel" Extract Data from Closedcalls Save Data Into Excel File As "Closedcalls".

    If Cancelcalls Select In Combobox1 Then Filter Start And End Date In Two Textboxes Then Click Cmd" Export Data To Excel" Extract Data from Cancelcalls Save Data Into Excel File As "Cancelcalls".


    "C:\Users\mani\Desktop\New folder\Lenvo_Reports\ONSITE Cases\Vlokupuf" This is path i stored existing 3 file dispath,closed,cancel
    Thanks in advance

    find the attahcment
    Attached Files Attached Files
    Last edited by johnodys; 06-05-2014 at 07:06 AM. Reason: explain

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2406 Win 11 Home 64 Bit
    Posts
    23,988

    Re: VBA export data to path dpends upon 1 combobox values sheets & 2 textbox date values

    This worked for me.

    Option Explicit
    
    
    Private Sub CommandButton1_Click()
        Dim wbk As Workbook
        Set wbk = ThisWorkbook
        Dim tgt As Workbook
        Dim w1 As Worksheet
        Dim w2 As Worksheet
        Dim w3 As Worksheet
        Set w1 = Sheets("DispatchCalls")
        Set w2 = Sheets("ClosedCalls")
        Set w3 = Sheets("CancelCalls")
        Dim i As Long
        Dim lr As Long
        Dim tlr As Long
        Dim sdte As Date
        Dim edte As Date
        sdte = Me.TextBox1
        edte = Me.TextBox2
        Dim aname As String
        Dim myPath As String
        myPath = "C:\Users\mani\Desktop\New folder\Lenvo_Reports\ONSITE Cases\Vlokupuf\"
        'myPath = "C:\Users\Alan Sidman\Desktop\"
    
    Application.ScreenUpdating = False
    If Me.ComboBox1 = "Dispatchcalls" Then
        aname = Me.ComboBox1
        Application.Workbooks.Add
        ActiveWorkbook.SaveAs (myPath & aname & ".xlsx")
        Set tgt = ActiveWorkbook
        wbk.Activate
        With w1
            .Range("A1:AQ1").Copy tgt.Sheets("Sheet1").Range("A1")
            lr = .Range("A" & Rows.Count).End(xlUp).Row
            For i = 2 To lr
            tlr = tgt.Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row
                If .Range("Y" & i) >= sdte And .Range("Y" & i) <= edte Then
                .Range("A" & i).EntireRow.Copy tgt.Sheets("Sheet1").Range("A" & tlr + 1)
                End If
            Next i
        End With
        Application.CutCopyMode = False
        tgt.Close
    
    ElseIf Me.ComboBox1 = "Closedcalls" Then
        aname = Me.ComboBox1
        Application.Workbooks.Add
        ActiveWorkbook.SaveAs (myPath & aname & ".xlsx")
        Set tgt = ActiveWorkbook
        wbk.Activate
        With w2
            .Range("A1:BA1").Copy tgt.Sheets("Sheet1").Range("A1")
            lr = .Range("A" & Rows.Count).End(xlUp).Row
            For i = 2 To lr
            tlr = tgt.Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row
                If .Range("AS" & i) >= sdte And .Range("AS" & i) <= edte Then
                .Range("A" & i).EntireRow.Copy tgt.Sheets("Sheet1").Range("A" & tlr + 1)
                End If
            Next i
        End With
        tgt.Close
        Application.CutCopyMode = False
        
        
    ElseIf Me.ComboBox1 = "Cancelcalls" Then
        aname = Me.ComboBox1
        Application.Workbooks.Add
        ActiveWorkbook.SaveAs (myPath & aname & ".xlsx")
        Set tgt = ActiveWorkbook
        wbk.Activate
        With w3
            .Range("A1:BA1").Copy tgt.Sheets("Sheet1").Range("A1")
            lr = .Range("A" & Rows.Count).End(xlUp).Row
            For i = 2 To lr
            tlr = tgt.Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row
                If .Range("AK" & i) >= sdte And .Range("AK" & i) <= edte Then
                .Range("A" & i).EntireRow.Copy tgt.Sheets("Sheet1").Range("A" & tlr + 1)
                End If
            Next i
        End With
    
        tgt.Close
    End If
        Application.CutCopyMode = False
        Application.ScreenUpdating = False
        MsgBox "Completed"
    
    
    End Sub

    Here is a tutorial for adding a Date Picker to your spreadsheet.

    https://www.youtube.com/watch?v=yQw73kRgkGI
    Last edited by alansidman; 06-05-2014 at 09:05 AM.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,125

    Re: VBA export data to path dpends upon 1 combobox values sheets & 2 textbox date values

    Here's my effort.

    I changed the textboxes to comboboxes, then only put unique dates in them.. This way, you can pick a start and stop date from the unique list.
    Attached Files Attached Files
    David
    (*) Reputation points appreciated.

  4. #4
    Forum Contributor
    Join Date
    07-23-2013
    Location
    bangalore
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    143

    Re: VBA export data to path dpends upon 1 combobox values sheets & 2 textbox date values

    Thanks Sir Amazing Efforts !!!
    Last edited by johnodys; 06-16-2014 at 02:22 AM. Reason: thanks

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 0
    Last Post: 11-04-2013, 01:48 PM
  2. [SOLVED] excel vba filter values to listbox from combobox and save edit values in textbox
    By breadwinner in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-03-2013, 08:42 AM
  3. Find UserForm ComboBox Value (date) & Transfer TextBox Data To Same Row
    By okriskao in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-30-2008, 11:33 AM
  4. Export Sheets Values to new Workbook
    By neodjandre in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 11-13-2007, 06:33 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1