Pasting a number as text

  • I currently have a central dataset workbook which opens a range of other workbooks, copies values and then pastes them in the Master workbook.


    When VBA stores a variable (as STRING) that looks like a number, it then Pastes the string as a number. I would like it to paste as TEXT.


    Please help! Relevant code is below


    Code
    Dim ProjID As String
    ProjID = Workbooks(myFile).Sheets("Timesheet").Range("a" & CyclCount).Value
    Range("A" & PstRw).Value = ProjID
  • In order to paste a number as a text. The range must first be formatted as text. So add this to your code before you paste the variable

    Code
    Range("A" & PstRw).NumberFormat = "@"
  • to format as text


    Code
    Range("A" & PstRw).Value = ProjID
    Range("A" & PstRw).NumberFormat = "@"

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!