Dim myArray As Variant
Dim lr As Long 'last row
Dim lc As Long 'last column
Dim dc As Long 'delete column
dc = 3
myArray = Cells(1).CurrentRegion
lr = UBound(myArray, 1)
lc = UBound(myArray, 2)
For x = 1 To lr
For y = dc To lc - 1
myArray(x, y) = myArray(x, y + 1)
If y = lc - 1 Then myArray(x, y + 1) = ""
Next y
Next x
If I have understood correctly, I think you can achieve that without any looping at all. In addition, you can swap the order of columns around if you want.Is it possible to pull in a table of data into an array and then delete a specific column of data? Perhaps one or more, if I determine that I only want certain columns of data? Looking for VBA code to perform this.
Sub SomeColumnsOnly()
Dim sCols As String
Dim aRws As Variant, aCols As Variant, DataArray As Variant
sCols = "4 5 8 1" '<- Columns of interest: D, E, H and A in that order
aCols = Split(sCols)
aRws = Evaluate("Row(2:20)") '<- This example is for rows 2:20
'This reads columns D, E, H and A into an array
DataArray = Application.Index(Columns("A:H"), aRws, aCols)
'This extracts columns 4 and 2 only, and in that order, from the above array
'That is, it will contain data from columns A & E of the worksheet
aRws = Evaluate("Row(1:" & UBound(DataArray) & ")") '<- Now we are interested in the 'rows' of DataArray
DataArray = Application.Index(DataArray, aRws, Array(4, 2))
End Sub