How to make a VBA copy move values with trailing zero's

philwojo

Well-known Member
Joined
May 10, 2013
Messages
533
I have some code that is moving data from a 'raw data' sheet to another sheet, but on the new sheet it is not moving the data with trailing zero's. How can I update this code to make sure it move all the raw data over as it is shown, I think I need to move it as Text, but I'm not fully sure how to do that.

Code:
Sub CopyRawdata()Dim copyRange As Range


Worksheets("PIF File Checker").Activate
Call Clearcells


Worksheets("Raw Data").Activate
   Set copyRange = Range("b2:b" & Range("A65536").End(xlUp).Row)
   With copyRange
       Sheets("PIF File Checker").Range("B7").Resize(.Rows.Count, .Columns.Count).Value = .Value
   End With
   
End Sub

Thanks,
Phil
 
This is now what I ended up with and it appears to be working, again not sure if it is the most elegant code, but it at least works.
Don't confuse lengthy with meaning it is not elegant! That is exactly how you want to do it. That is how Text to Columns works. If you leave off the Array values, it will default all fields to General.
I see that you changed them all to 2 "Text". That is fine, if you want all the fields to be "Text". Note that they can all be different (so you have some General, some Text, some Date, some "Do Not Import").

There is one minor thing you can do to shorten up your code a little. Whenever you have one line that ends in ".Select" and the next line starts with "Selection" or "ActiveCell", you can usually combine those lines (it isn't necessary to select ranges to work with them, and it actually speeds up your code to eliminate them).

So you can combine these two lines:
Code:
Range("b7:bf6000").Select
Selection.NumberFormat = "@"
to this single line:
Code:
Range("b7:bf6000").NumberFormat = "@"
 
Last edited:
Upvote 0

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Thanks, I made that change and it is working as expected, again I appreciate the extra knowledge and it makes sense.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top