Copy Columns in Sheets
Budget: $10 – $30 USD
I have the next code:
Sub CopyColumnsToSheets()
Dim i As Long
Dim ws As Worksheet
Dim tableData As Variant
Dim sheetData As Variant
Dim dataSheet As Worksheet
Dim listSheet As Worksheet
Dim sheetList As Variant
Dim sheetName As String
Dim numColumns As Long
Dim numRows As Long
' Set the data sheet and the range of table data
Set dataSheet = Sheets("Matriz 22")
tableData = dataSheet.Range("C1:FF2190").Value
' Set the list sheet
Set listSheet = Sheets("Sheet2")
' Set the array of sheet names from the list sheet
sheetList = listSheet.Range("A2:A161").Value
' Set the number of columns and rows in the table data
numColumns = UBound(tableData, 2)
numRows = UBound(tableData, 1)
' Loop through the columns of the table data and copy each column to an existing sheet
For i = 1 To numColumns
sheetName = sheetList(i, 1)
Set ws = Sheets(sheetName)
sheetData = Application.Transpose(Application.Transpose(tableData))
ws.Range("C1").Resize(numRows, 1).Value = sheetData
Next i
End Sub
The problem is that I need to copy only the column 1 of the matrix into my sheet 1 already created into the cell C1, and copy only the column 2 of the matrix into my sheet 2 already created into the same range of C1, my issue is that the code only copies me column 1 into every sheet already created, how can I fix the code or write a new one to do what I need?
Sub CopyColumnsToSheets()
Dim i As Long
Dim ws As Worksheet
Dim tableData As Variant
Dim sheetData As Variant
Dim dataSheet As Worksheet
Dim listSheet As Worksheet
Dim sheetList As Variant
Dim sheetName As String
Dim numColumns As Long
Dim numRows As Long
' Set the data sheet and the range of table data
Set dataSheet = Sheets("Matriz 22")
tableData = dataSheet.Range("C1:FF2190").Value
' Set the list sheet
Set listSheet = Sheets("Sheet2")
' Set the array of sheet names from the list sheet
sheetList = listSheet.Range("A2:A161").Value
' Set the number of columns and rows in the table data
numColumns = UBound(tableData, 2)
numRows = UBound(tableData, 1)
' Loop through the columns of the table data and copy each column to an existing sheet
For i = 1 To numColumns
sheetName = sheetList(i, 1)
Set ws = Sheets(sheetName)
sheetData = Application.Transpose(Application.Transpose(tableData))
ws.Range("C1").Resize(numRows, 1).Value = sheetData
Next i
End Sub
The problem is that I need to copy only the column 1 of the matrix into my sheet 1 already created into the cell C1, and copy only the column 2 of the matrix into my sheet 2 already created into the same range of C1, my issue is that the code only copies me column 1 into every sheet already created, how can I fix the code or write a new one to do what I need?