0
Sub tranpose()

  
Dim sourceRange As Range
  
Dim targetRange As Range
  
Dim X As Integer
  
X = 0


While (X < 6)

  
Set sourceRange = ActiveWorkbook.Sheets("Main Sheet").Range(Cells(1 + X, 1), Cells(1 + X,5))
  Set targetRange = ThisWorkbook.Worksheets("Printout Template").Cells(1 + 5 * X, 1)
  

  sourceRange.Copy
  targetRange.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, transpose:=True
  
X = X + 1


Wend


End Sub

So I'm trying to make a macro that copies the first 5 columns of each row in a first sheet (Main Sheet) and transposes while pasting it into a second sheet (Printout Template). As I've never coded in VBA I seem to be drowning in this new syntax. I think what I want is implemented in the code above but I keep getting an error 1004 (Application-Defined or Object-Defined error) and can't seem to debug by sifting through online forums of past problems. Note: The while loop is currently temporary (eventually I will implement a more formal while loop to do all the initial sheet and stop on the next blank entry). Any help is greatly appreciated. Thanks!

I must be misunderstanding how vba uses its functions in the excel sheet because this code runs when I don't put the x variable inside the cell to generalize the procedure.

A03
  • 33
  • 5

0 Answers0