Stop Excel from automatically converting certain text values to dates

前端 未结 30 2659
别跟我提以往
别跟我提以往 2020-11-22 04:16

Does anyone happen to know if there is a token I can add to my csv for a certain field so Excel doesn\'t try to convert it to a date?

I\'m trying to write a .csv fil

30条回答
  •  旧时难觅i
    2020-11-22 05:06

    I made this vba macro which basically formats the output range as text before pasting the numbers. Works perfect for me when i want to paste values such as 8/11, 23/6, 1/3 etc. without Excel interpreting them as dates.

    Sub PasteAsText()
    ' Created by Lars-Erik Sørbotten, 2017-09-17
    Call CreateSheetBackup
    
    Columns(ActiveCell.Column).NumberFormat = "@"
    
    Dim DataObj As MSForms.DataObject
    Set DataObj = New MSForms.DataObject
    DataObj.GetFromClipboard
    
    ActiveCell.PasteSpecial
    
    End Sub
    

    I'm very interested in knowing if this works for other people as well. I've been looking for a solution to this problem for a while, but I haven't seen a quick vba solution to it before which didn't include inserting ' in front of the input text. This code retains the data in its original form.

提交回复
热议问题