Requirement:
The user has 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.
The user would like it to paste as TEXT.
Relevant code is below:
Dim ProjID As String ProjID = Workbooks(myFile).Sheets("Timesheet").Range("a" & CyclCount).Value Range("A" & PstRw).Value = ProjID
Solution:
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:
Range("A" & PstRw).NumberFormat = "@"
OR
To format as text
Range("A" & PstRw).Value = ProjID Range("A" & PstRw).NumberFormat = "@"
Obtained from the OzGrid Help Forum.
Solution provided by chirayuw and rapsofty.
See also: Index to Excel VBA Code and Index to Excel Freebies and Lesson 1 - Excel Fundamentals and Index to how to… providing a range of solutions and Index to new resources and reference sheets
See also:
How to extract text from a string before a last specified character |
How to extract text string |
How to alternate row colours based on text name |
How to sum cell numerical values based on text suffix |
Click here to visit our Free 24/7 Excel/VBA Help Forum where there are thousands of posts you can get information from, or you can join the Forum and post your own questions.