howCopy data on sheet1 to sheet1 Transpose it using loop metod

alex0405

New Member
Joined
Jun 15, 2012
Messages
1
Hi every one, i am beginner in Vba,

I have problem resolving my VBA code. for my office task that my superior ask me to
i wont to copy data in sheet1 to sheet2 and Transpose it.
i try to Use VBA code to solve it.

this is the code that i made :

Sub macro()
Dim i As Integer
Dim x As Integer
Dim j As Integer
Dim b As Integer
Worksheets("Sheet1").Range("A1").Select
Worksheets("Sheet1").Range("A2:A33").Copy
Worksheets("Sheet2").Range("B1").PasteSpecial Transpose:=True
Worksheets("Sheet2").Range("A1") = "EMITEN"
i = 1
x = 1
j = 2
b = 4
Do While Worksheets("Sheet1").Range("Ai").Value <> ""
If Range("ai").Value <> "" Then
j = j + 1
x = x + 32
Worksheets("Sheet1").Range("A").Copy
Worksheets("sheet1").Range("B").PasteSpecial Paste:=xlValues
Worksheets("Sheet1").Range("B:D[x]").Copy
Worksheets("Sheet2").Range("A[j]").PasteSpecial Transpose:=True
Worksheets("Sheet2").Range("A[j]:A").Value = Worksheets("Sheet2").Range("A[j]")
x = x + 2
i = i + 34
j = j + 2
b = j + 2
Else: End If
Loop
End Sub
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().

AlphaFrog

MrExcel MVP
Joined
Sep 2, 2009
Messages
16,402
Create a range reference using something like this...

.Range("A" & i)

.Range("B" & i & ":D" & x)


 

Watch MrExcel Video

Forum statistics

Threads
1,130,118
Messages
5,640,216
Members
417,131
Latest member
Seanr19871

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
Top