I am seeking for help I have thousands of unit ID that I need to copy and paste transpose manually. Here is the situation if column C Seq no. is the same for example Seq 1 then I need to copy column B unit ID and paste transpose to column D and I need to do that to the rest of the column
-
Did you try recording a macro whilst doing it? You could apply a filter on col C , then find the last row and then construct a range from Range("B2:B" & LastRow) and pass that to Application.WorksheetFunction.Transpose. There are limits to transpose though. See this question: stackoverflow.com/questions/20055784/…. This will help with transpose part excel-vba-range-copy-transpose-pasteQHarr– QHarr2018-01-21 14:00:53 +00:00Commented Jan 21, 2018 at 14:00
-
Possible duplicate of Excel VBA code for copy and transposeashleedawg– ashleedawg2018-01-21 16:48:17 +00:00Commented Jan 21, 2018 at 16:48
Add a comment
|
1 Answer
Try this:
Sub TransposeUnitID()
Dim data As Variant, seq_number As Integer, rw as Long
data = Range("B2:C21").Value '~~>Update as necessary
seq_number = data(1, 2)
rw = 2
For i = 1 To UBound(data)
If data(i, 2) <> seq_number Then
seq_number = data(i, 2)
rw = i + 1
End If
Range("B" & rw).End(xlToRight).Offset(0, 1) = data(i, 1)
Next i
End Sub
Notes:
- Reads your data in as an array
- Assume
Seqis ordered (as per example) - Loop over array and keep track of
Seqto printUnitIDto correct cell
6 Comments
ramon
@ alex P thank you so much this really helps i just want to ask how can i extend the range data = Range("B2:C99").Value tried to maximize to thousand but got error i want to extend on the whole column c
Alex P
Just replace the range with Range(“B2:C99”).value.
ramon
Im getting error if i change to more than thousand Range(“B2:C1900”).value
ramon
It says run time error 1004: apllication- defined or object defined error
ramon
i got error on this line Range("B" & rw).End(xlToRight).Offset(0, 1) = data(i, 1)
|
