ItalianPlatinum
Well-known Member
- Joined
- Mar 23, 2017
- Messages
- 843
- Office Version
- 365
- 2019
- Platform
- Windows
Hi - I have an existing VBA that was provided to me by someone here on the site, it works great. I have one change required that is resulting in this VBA to no longer be of use. Is someone able to help?
Essentially previously all the data was transferred over with columns next to each other now the destination path is changing where columns are no longer all next to each other so for example:
Column A to Column B
Column G to Column D
Column L to Column F
Essentially previously all the data was transferred over with columns next to each other now the destination path is changing where columns are no longer all next to each other so for example:
Column A to Column B
Column G to Column D
Column L to Column F
VBA Code:
Dim UsdRws As Long
Dim FilePath As String
Dim TestStr As String
Dim FoundFile As Boolean
Dim rws As Long
Dim bottomrow, lastblank As Long
Dim lr As Long
Dim vCols As Variant, vRows As Variant
Dim i As Long, k As Long
Dim ErrMsg As String
Dim ST As Workbook
Dim wbNCOMP As Workbook
Dim wsComp As Worksheet, wsComp1 As Worksheet, wsDIST As Worksheet, wsDIST1 As Worksheet, wsDV As Worksheet, wsDT As Worksheet
Dim wb As Excel.Workbook
'set shortcut for with sheets
With ThisWorkbook
Set wsComp = .Sheets("Compare")
Set wsDIST = .Sheets("Periodic")
Set wsDV = .Sheets("NAS D")
Set wsDT = .Sheets("NAS DT")
End With
'set shortcut for sheet w/o WITH & ThisWorkbook
Set wsComp1 = Sheets("Compare")
Set wsDIST1 = Sheets("Periodic")
'transfer data over to Compare tab
vCols = Array(1, 9, 10, 11, 2, 3, 4, 5, 6, 7, 8) '<- Columns of interest in specified order
With wsDIST
With .Range("A1:K" & .Range("I" & rows.count).End(xlUp).row)
If .rows.count > 2 Then
vRows = Application.Index(.Cells, Evaluate("row(1:" & .rows.count & ")"), Array(9, 3))
For i = 3 To UBound(vRows)
If Len(vRows(i, 1)) > 0 And UCase(vRows(i, 2)) = "INCM" Then
k = k + 1
vRows(k, 1) = i
End If
Next i
wsComp.Range("A13").Resize(k, UBound(vCols) + 1).Value = Application.Index(.Cells.Value, Application.Index(vRows, 0, 1), vCols)
Else
MsgBox "No data to transfer"
End If
End With
End With