I have 59 csvs in the same folder that contain field names in column B. A1 contains just the filename. The csvs need to be set up in a certain way to facilitate data migration to a state database. I would like to transpose the data in column B as rows (for example, instead of field names in B1:B5, I would like data from B1:F1). While the range size varies by csv (we have csvs with only 5 values while others have more than 30), the ranges are all contiguous. I can't even transpose a single csv--I was hoping to throw the following code into a Do While or For Next loop:
I am defining the range as the FieldNames variable with lrow because the range size will vary with each csv--lrow allows me to exploit the contiguity of the data. Unfortunately, I encountered this error message:
.
VBA Code:
Sub TranposeData()
Dim FieldNames As Range
Dim lrow As Integer
lrow = Cells(Rows.Count, 2).End(xlUp).Row
Debug.Print lrow
Set FieldNames = Range("B1:B" & lrow)
FieldNames.Cut
Sheets(1).Range("B1").PasteSpecial Transpose:=True
End Sub
I am defining the range as the FieldNames variable with lrow because the range size will vary with each csv--lrow allows me to exploit the contiguity of the data. Unfortunately, I encountered this error message:
.