Weird Date change when copying a Worksheet into a new workbook

0 votes

When I use the following code to create a new workbook with a copied sheet there is a strange date change that occurs:

Worksheets("Week Template").Copy
Set Newwb = ActiveWorkbook
NewwbName = ActiveWorkbook.Name

Windows("Mainworkbook.xlsm").Activate
Sheets("Week Template").Select
    Range("B3:B13").Select
    Application.CutCopyMode = False
    Selection.Copy

Workbooks(NewwbName).Worksheets("Week Template").Activate
Range("B3").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False

For example, if I copied the date "1/1/2023" it is changed to "12/31/2018"

however, when I change the format of the cells to text, the numbers are the same, "43465"

Does anyone know how I can resolve this issue?

Jan 10 in Others by Kithuzzz
• 28,700 points
45 views

1 answer to this question.

0 votes

Try  this:

    Dim wb As Workbook, wbNew As Workbook, wsTempl As Worksheet
    
    Set wb = ThisWorkbook 'for example, if it's the workbook where this code runs
    Set wsTempl = wb.Worksheets("Week Template")
    
    wsTempl.Copy
    Set wbNew = ActiveWorkbook 'has the copied sheet
    wbNew.Worksheets(wsTempl.Name).Range("B3:B13").Value = wsTempl.Range("B3:B13").Value
answered Jan 10 by narikkadan
• 53,160 points

Related Questions In Others

0 votes
1 answer
0 votes
1 answer

How do I protect all worksheet in an Excel workbook with a single click?

VBA Code : Dim ws as Worksheet Dim pwd ...READ MORE

answered Oct 22, 2022 in Others by narikkadan
• 53,160 points
73 views
0 votes
1 answer

How to change two different date format into single date format in excel

With data in A2, in B2 enter: =IF(ISNUMBER(A2),A2,DATE(LEFT(A2,4),MID(A2,6,2),RIGHT(A2,2))) and apply your format ...READ MORE

answered Dec 24, 2022 in Others by narikkadan
• 53,160 points
53 views
0 votes
1 answer

How to unmerge multiple cells and transpose each value into a new column in Pandas dataframe from excel file

Try this: df = pd.read_excel("Sample_File.xlsx", header=[0,1,2,3,4,5], index_col = ...READ MORE

answered Jan 8 in Others by narikkadan
• 53,160 points
108 views
0 votes
1 answer

Retrieve epay.info Balance with VBA and Excel

This code should log you in, provided ...READ MORE

answered Sep 5, 2018 in Blockchain by digger
• 26,740 points
529 views
0 votes
1 answer

How to load file to Excel Power query from SFTP site

Currently, I don't think there is a ...READ MORE

answered Dec 3, 2018 in Power BI by Upasana
• 8,620 points
2,408 views
0 votes
1 answer

Using VBA Excel to create a gramatically correct list

The Excel AND function is a logical ...READ MORE

answered Feb 9, 2022 in Others by gaurav
• 22,940 points
117 views
0 votes
2 answers

How to copy a formula horizontally within a table using Excel VBA?

Hi so basically, create an adjacent column ...READ MORE

answered Feb 16, 2022 in Others by Edureka
• 13,630 points
294 views
0 votes
1 answer
0 votes
1 answer

VBA to unhide a column when opening a workbook

Use the workbook_open even within ThisWorkbook. READ MORE

answered Oct 20, 2022 in Others by narikkadan
• 53,160 points
67 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP