Results 1 to 5 of 5

How to combine a code and a macro

Threaded View

  1. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,524

    Re: How to combine a code and a macro

    Try this,
    I used a sheet names "Start". When you run the code, the code will delete all the sheets except sheets("Start")
    
    Sub OPenMultipleWorkbooks()
    'Open Multiple .csv files, this workbooks name is, 'Compare Workbook.xlsm'
        Dim wb As Workbook
        Dim GetFile As Variant
    
        Set wb = ThisWorkbook
        Application.DisplayAlerts = False
        
        For Each Sheet In Sheets
            If Sheet.Name <> "Start" Then Sheet.Delete
        Next Sheet
        ChDrive "C:"
    
        GetFile = Application.GetOpenFilename(FileFilter:="CSV (*.CSV), *.CSV", Title:="Open CSV File", MultiSelect:=True)
        Application.ScreenUpdating = False
    
        On Error Resume Next
    
        If GetFile <> False Then
            On Error GoTo 0
            For i = 1 To UBound(GetFile)
    
                Workbooks.Open Filename:=GetFile(i)
                Sheets(1).Move Before:=wb.Sheets(1)
    
            Next i
        End If
        CombineDts
    End Sub
    Sub CombineDts()
        Dim LstRw As Long, rng As Range, sh As Worksheet
        Dim Frmla As String
    
        Frmla = "=DATEVALUE(C2&"" / ""&D2&"" / ""&B2)"
        For Each sh In Sheets
            With sh
                If .Range("A1") = "ID" Then
                    LstRw = .Cells(.Rows.Count, "A").End(xlUp).Row
                    Set rng = .Range("A2:A" & LstRw)
                    rng = Frmla
                    rng.Value = rng.Value
                    rng.NumberFormat = "dd/mm/yyyy"
                    .Range("A1") = "Date"
                    .Columns("B:D").Delete Shift:=xlToLeft
                End If
            End With
        Next sh
    End Sub
    Attached Files Attached Files
    Last edited by davesexcel; 12-20-2015 at 09:43 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Combine two pieces of code together
    By ttontis in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-29-2015, 12:41 PM
  2. [SOLVED] how to combine code
    By ammartino44 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-05-2015, 02:02 PM
  3. [SOLVED] Change Event Code too long - Need to combine 2 events into 1 macro
    By Sc0tt1e in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-15-2014, 03:57 AM
  4. [SOLVED] If code same combine the description
    By Klitos in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 03-28-2013, 05:16 AM
  5. [SOLVED] Combine code in VBA
    By clifton1230 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-16-2013, 12:21 AM
  6. [SOLVED] Using Combine macro to combine multiple worksheets - need to modify to paste formulas
    By DLSmith in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-26-2012, 09:07 AM
  7. combine code
    By Dennisli2000 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-12-2008, 12:17 AM

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