VBA code to copy columns from one WB to another in a specific order.

thardin

Board Regular
Joined
Sep 29, 2021
Messages
137
Office Version
  1. 365
Platform
  1. Windows
What is a more effective way to write this code?

I'm trying to copy and paste columns from one workbook to another in a certain order.
If you look at the code, When I run the code 1 section at a time it will work, but if I run it all together it doesn't work like I want.

What is a better way to achieve this?
Thanks.

1636114209975.png
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
How about
VBA Code:
Sub thardin()
   Dim Ary As Variant
   Dim Fname As String
   
   Fname = "Test1" & Format(Date - 1, "mmddyy")
   With Workbooks(Fname & ".xlsx").Sheets("UBTList").UsedRange
      Ary = Application.Index(.Value, .Worksheet.Evaluate("row(1:" & .Rows.Count & ")"), Array(4, 1, 2))
   End With
   Workbooks(Fname & ".csv").ActiveSheet.Range("A1").Resize(UBound(Ary), 3).Value = Ary
End Sub

In future please post you code, not an image of it. How to Post Your VBA Code
 
Upvote 0
Solution
I think I am having an issue with this method of copying and pasting.
I noticed if a number in a cell starts with 0, when the data is pasted, it doesn't keep the zero.

How do I fix this?
 
Upvote 0

Forum statistics

Threads
1,215,222
Messages
6,123,704
Members
449,118
Latest member
MichealRed

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