macro to copy paste

ariel_jaan

New Member
Joined
Aug 26, 2007
Messages
15
Good day to all.

I have a problem with my worksheet.
Let me give you an example

BEFORE
Sheet 1
Column A
quick
brown
fox

jumps
over

AFTER
Sheet 2
Column A Column B Column C Column D Column E
quick brown fox
jumps over

Can someone help me with a macro for this? Basically the macro will only select the filled rows in Sheet 1 Column A and then paste it to Sheet 2 Column A but transpose though. Also, the next filled rows will then be copy paste to Sheet 2. If you notice the space in Column A Sheet 1 represents the row cut in Sheet 2. I have like 200 rows and 60 spaces manually doing the copy paste would feel like forever please someone great there please help me with my assignment.

Thanks a lot and good luck!!!
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
ariel_jaan,


please help me with my assignment

I hope that this is not for a homework assignment.



Sample worksheets before the macro:


Excel Workbook
A
1quick
2brown
3fox
4
5jumps
6over
7
Sheet1





Excel Workbook
ABC
1
2
3
Sheet2





After the macro:


Excel Workbook
ABC
1quickbrownfox
2jumpsover
3
Sheet2





Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).


1. Copy the below code, by highlighting the code and pressing the keys CTRL + C
2. Open your workbook
3. Press the keys ALT + F11 to open the Visual Basic Editor
4. Press the keys ALT + I to activate the Insert menu
5. Press M to insert a Standard Module
6. Where the cursor is flashing, paste the code by pressing the keys CTRL + V
7. Press the keys ALT + Q to exit the Editor, and return to Excel
8. To run the macro from Excel, open the workbook, and press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.


Code:
Option Explicit
Sub ReorgData()
' hiker95, 05/16/2011
' http://www.mrexcel.com/forum/showthread.php?t=550246
Dim w1 As Worksheet, w2 As Worksheet
Dim Area As Range, NR As Long
Application.ScreenUpdating = False
Set w1 = Worksheets("Sheet1")
If Not Evaluate("ISREF(Sheet2!A1)") Then Worksheets.Add(After:=w1).Name = "Sheet2"
Set w2 = Worksheets("Sheet2")
NR = 1
For Each Area In w1.Range("A1", w1.Range("A" & Rows.Count).End(xlUp)).SpecialCells(xlCellTypeConstants).Areas
  With Area
    w2.Range("A" & NR).Resize(, .Rows.Count).Value = Application.Transpose(w1.Range("A" & .Row).Resize(.Rows.Count))
    NR = w2.Range("A" & Rows.Count).End(xlUp).Offset(1).Row
  End With
Next Area
w2.UsedRange.Columns.AutoFit
w2.Activate
Application.ScreenUpdating = True
End Sub


Then run the ReorgData macro.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,504
Messages
6,179,142
Members
452,892
Latest member
JUSTOUTOFMYREACH

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