Solved: Copy a Range then Transpose Paste into every other Cell
I'm copying a range of 20 cells (C9:C28) from one Workbook into my Active Workbook, but want to transpose the paste into every other cell (D5, F5, H5, J5, L5, etc... out to AP5).
There is data in the skipped cells (E5, G5, I5, K5, M5, etc.., out to AQ5) that I need to avoid "stepping on".
I will be copying over 200 Ranges from 200 different files so I will be incremanting the Row (5 in this example) as I loop through the 200 files if that makes a difference in the solution.
Any ideas?
As always, Thanks...
JimS
Copy a Range then Transpose "Values" into every other Cell
Thanks for your responses.
Ken is correct in that I only need the Values (not any formatting). I'm not skilled enough in VBA to figure out how Ken's code is supposed to work, but will continue to try and figure it out.
Below is a chunky piece of code that I have put together that will work (almost).
It references a range name ("files"), which is a list of file names to determine which file to open in the source folder.
The 1st issue is that the source files all have the same Data Validation which is getting copied over and causing the standard error message about duplicate "names" - which I haven't figured out a fix for yet.
PLUS, since I'm actually opening the "input" files I'm worried about memory issues when I have to open 100's of files, not to mention speed.
So if I can do this without actually opening the input files and not copying any formats (data validation/names) I think that would be the best solution. I just can't figure out how Ken's code works.
Thanks again for your help, or any other suggestions...
JimS
[vba]
Sub Import_Data()
Dim myDir As String, r As Range, fn As String, msg As String
Dim x As Integer
Dim c As Integer
Dim w As Integer
myDir = "C:\Test\Test Data Files\"
x = 5
For Each r In Range("files")
fn = Dir(myDir & r.Value)
If fn = "" Then
msg = msg & vbLf & r.Value
Else
With Workbooks.Open(myDir & fn) ' copies Names to Column A, B & C
.Sheets("Name").Range("B7").Copy _
ThisWorkbook.Sheets("Data").Range("A" & x)
.Sheets("Name").Range("B9").Copy _
ThisWorkbook.Sheets("Data").Range("B" & x)
.Sheets("Name").Range("B11").Copy _
ThisWorkbook.Sheets("Data").Range("C" & x)
w = 4
For c = 9 To 28 'copies C9:C28 to D,F,H,J,L,N etc...
.Sheets("Votes").Cells(c, 3).Copy _
ThisWorkbook.Sheets("Data").Cells(x, w)
w = w + 2
Next c
w = 5
For c = 9 To 28 'copies C9:C28 to E,G,I,K,M,O etc...
.Sheets("Votes").Cells(c, 5).Copy _
ThisWorkbook.Sheets("Data").Cells(x, w)
w = w + 2
Next c
End With
x = x + 1
With Workbooks.Open(myDir & fn)
.Close False
End With
End If
Next
If Len(msg) Then
MsgBox "Not found" & msg
End If
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Application.Calculation = xlAutomatic
End Sub
[/vba]