Trouble Copying Columns from One Sheet to Another Using VBA

monicamarie

Board Regular
Joined
Sep 2, 2008
Messages
72
Office Version
  1. 365
Hello.
I have a worksheet (Sheet1) with 8 columns of data starting on Row 1. The column names are Cust Number, Created On, Account, Problem, State, ST, System Type and Ticket. (Not always in that order)
The code below is used to copy specific columns from sheet 1 to a new created worksheet called Service Queue.
The problem is that for some reason, it's not copying the column named "ST" from Sheet 1 but instead it's copying a column called "State" Can someone help me to fix this issue?

Sub MoveColumns()
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim i As Integer

Sheets.Add.Name = "Service Queue"
Set ws1 = Worksheets("Sheet1")
Set ws2 = Worksheets("Service Queue")
myColumns = Array("Cust Number", "Created On", "ST")


With ws1.Range("A1:H1")
For i = 0 To UBound(myColumns)
On Error Resume Next
.Find(myColumns(i)).EntireColumn.Copy Destination:=ws2.Cells(1, i + 1)
Err.Clear
Next i
End With
Set ws1 = Nothing
Set ws2 = Nothing


End Sub
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
That's what happens when you don't use the various paremeters of Find I'm afraid (it will use whatever it's previous settings were).
Try...
VBA Code:
.Find(What:=myColumns(i), LookAt:=xlWhole).EntireColumn.Copy Destination:=ws2.Cells(1, i + 1)
 
Upvote 0

Forum statistics

Threads
1,214,976
Messages
6,122,541
Members
449,089
Latest member
davidcom

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