Question : Format Date Value in column

Hi Experts,

I would like to request Experts help to add an additional feature in the attached script. How to make sure the paste data value at Column_B is always with date format (dd-mmm)?. Hope Experts can help me. Attached the portion of the code for Experts perusal.
1:
2:
3:
4:
5:
6:
7:
8:
Set wb = Workbooks.Open(strFilePath)
        wb.Activate
        intSrcRows = wb.Worksheets(1).Cells(Cells.Rows.Count, "A").End(xlUp).Row
        Set copyRange = wb.Worksheets(1).Range("B6:B" & intSrcRows)
        Set copyRange = Union(copyRange, copyRange.Offset(, 4), copyRange.Offset(, 6).Resize(, 6))
        copyRange.Copy
        
        Set lcTargetCell = ThisWorkbook.Worksheets(2).Range("A" & Rows.Count).End(xlUp).Offset(1)

Answer : Format Date Value in column

Why do you have all the Activate stuff?

I've got a feeling that it might be mucking up your PasteSpecial, perhaps causing there to be nothing to actually paste.

You might also want to consider the order you are doing things.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
Option Explicit

Sub Copy_Paste3()
Dim wb As Workbook
Dim objFileDLG As Office.FileDialog
Dim strFilePath, lcTargetCell
Dim intSrcRows As Integer
Dim intTgtRows As Integer

    ChDir "D:\Data\"
    Set objFileDLG = Application.FileDialog(msoFileDialogFilePicker)
    Dim copyRange As Range

    intTgtRows = 2

    Do While True
        strFilePath = ""
        With objFileDLG
            .Filters.Add "Excel Files", "*.xls", 1
            .FilterIndex = 1
            .AllowMultiSelect = False
            .Title = "Select The Workbook to copy From "
            If .Show() <> 0 Then
                strFilePath = .SelectedItems(1)
            End If
        End With

        If Trim(strFilePath) = "" Then Exit Do

        Set wb = Workbooks.Open(strFilePath)

        intSrcRows = wb.Worksheets(1).Cells(Cells.Rows.Count, "A").End(xlUp).Row

        Set copyRange = wb.Worksheets(1).Range("B6:B" & intSrcRows)

        Set copyRange = Union(copyRange, copyRange.Offset(, 4), copyRange.Offset(, 6).Resize(, 6))

        copyRange.Copy

        Set lcTargetCell = ThisWorkbook.Worksheets(2).Range("A" & Rows.Count).End(xlUp).Offset(1)

        lcTargetCell.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
                                  xlNone, SkipBlanks:=False, Transpose:=False

        ThisWorkbook.Worksheets(2).Range("B:B").NumberFormat = "dd-mmm"

        Application.CutCopyMode = False
        
        wb.Close
        
        Set wb = Nothing

        intTgtRows = intTgtRows + intSrcRows - 1
        
    Loop
    'new lines

    On Error Resume Next

    ThisWorkbook.Worksheets(1).Columns(1).SpecialCells(xlBlanks).EntireRow.Delete
End Sub
Random Solutions  
 
programming4us programming4us