VBA code from rows to columns not working

Lyrad39

New Member
Joined
Jun 14, 2023
Messages
9
Office Version
  1. 2016
Platform
  1. Windows
Good day community,

I am having some issues with my codes that were supposed to transpose from rows to columns in sheet 4 as shown in the first photo. However, with a new worksheet the codes seem to transpose the columns differently as shown in "JUL" and "SHEET4". Any help would be greatly appreciated and thank you in advance!

Here are the codes:

VBA Code:
Sub Transpose_PasteSpecial()

Range("A1:S219").Copy
Worksheets("Sheet4").Range("A4").PasteSpecial Transpose:=True
  
  Dim Lastcol As Long, c As Long
  
  Worksheets("Sheet4").Activate
  
  Lastcol = Cells.Find(What:="*", LookIn:=xlValues, SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column
  For c = 11 To Lastcol Step 10
    Cells(5, c).Resize(16, 10).Cut Destination:=Range("C" & Rows.Count).End(xlUp).Offset(1, -2)
  Next c
  ActiveSheet.UsedRange.Offset(, 10).ClearContents
  
End Sub
 

Attachments

  • Proper format.PNG
    Proper format.PNG
    75.6 KB · Views: 21
  • JUL.PNG
    JUL.PNG
    103 KB · Views: 11
  • SHEET 4.PNG
    SHEET 4.PNG
    95.3 KB · Views: 27

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Your setup seems to be quite complicated. I can give a basic example:
VBA Code:
Sub test()
  Dim tmp As Variant, myRange as Variant
  tmp = Range("A1:D4")
  myRange = Application.Transpose(tmp)
  Range("A1").Resize(UBound(myRange,1),Ubound(myRange,2)) = myRange
End Sub
Note that Application.Transpose will convert single-column ranges into a 1D array. You will require a different setup.
VBA Code:
Sub test()
  Dim tmp As Variant, myRange as Variant, tmp2() As Variant
  tmp = Range("A1:D4")
  If UBound(tmp,2)=1 Then
    Redim tmp2(1 to 1, 1 To Ubound(tmp))
    For i = 1 to Ubound(tmp)
      tmp2(1,i) = tmp(i,1)
      
    Next
Range("A1").Resize(,Ubound(tmp2,2)) = myRange
  Else
    myRange = Application.Transpose(tmp)    Range("A1").Resize(UBound(myRange,1),Ubound(myRange,2)) = myRange
  End If
End Sub
 
Last edited by a moderator:
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,264
Members
452,627
Latest member
KitkatToby

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top