How to copy data from rows with value to a new sheet using macro
Closed
ospeng
Posts
2
Registration date
Wednesday October 15, 2014
Status
Member
Last seen
October 22, 2014
-
Oct 15, 2014 at 05:41 PM
TrowaD Posts 2921 Registration date Sunday September 12, 2010 Status Moderator Last seen December 27, 2022 - Oct 28, 2014 at 11:55 AM
TrowaD Posts 2921 Registration date Sunday September 12, 2010 Status Moderator Last seen December 27, 2022 - Oct 28, 2014 at 11:55 AM
Related:
- How to copy data from rows with value to a new sheet using macro
- Google sheet right to left - Guide
- Excel macro to create new sheet based on value in cells - Guide
- Windows network commands cheat sheet - Guide
- Transfer data from one excel worksheet to another automatically - Guide
- How to open excel sheet in notepad++ - Guide
2 responses
TrowaD
Posts
2921
Registration date
Sunday September 12, 2010
Status
Moderator
Last seen
December 27, 2022
555
Oct 16, 2014 at 11:03 AM
Oct 16, 2014 at 11:03 AM
Hi Ospeng,
Manually create the header in sheet2, then run the following code:
How to implement and run a code:
- From Excel hit Alt + F11 to open the "Microsoft Visual Basic" window.
- Go to the top menu in the newly opened window > Insert > Module.
- Paste the code in the big white field.
- You can now close this window.
- Back at Excel, hit Alt + F8 to display the available macro's.
- Double-click the macro you wish to run.
NOTE: macro's cannot be reversed using the blue arrows. Always make sure you save your file before running a code, so you can reopen your file if something unforeseen happens.
Best regards,
Trowa
Manually create the header in sheet2, then run the following code:
Sub RunMe() Dim iCol As Long iCol = 2 Sheets("Sheet1").Select Do Sheets("Sheet2").Range("B" & Rows.Count).End(xlUp).Offset(1, 0) = Cells(1, iCol) iCol = iCol + 1 Loop Until IsEmpty(Cells(1, iCol)) For Each cell In Range(Range("A2"), Range("A" & Rows.Count).End(xlUp)) Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1, 0) = cell Sheets("Sheet2").Range("C" & Rows.Count).End(xlUp).Offset(1, 0) = cell.Offset(0, 2) Sheets("Sheet2").Range("D" & Rows.Count).End(xlUp).Offset(1, 0) = cell.Offset(0, 1) Next cell End Sub
How to implement and run a code:
- From Excel hit Alt + F11 to open the "Microsoft Visual Basic" window.
- Go to the top menu in the newly opened window > Insert > Module.
- Paste the code in the big white field.
- You can now close this window.
- Back at Excel, hit Alt + F8 to display the available macro's.
- Double-click the macro you wish to run.
NOTE: macro's cannot be reversed using the blue arrows. Always make sure you save your file before running a code, so you can reopen your file if something unforeseen happens.
Best regards,
Trowa
ospeng
Posts
2
Registration date
Wednesday October 15, 2014
Status
Member
Last seen
October 22, 2014
Oct 22, 2014 at 03:07 AM
Oct 22, 2014 at 03:07 AM
Thank you again for your help, but I am having trouble with the code. The codes are not copying down for all sales rep. I am a novice to macro. Below is a sample of the raw data:
ID 10 55 65 85
3351 - - - 24.00
3356 - 1,200.00 - -
3357 - - - -
3358 - 1,200.00 - -
3360 - 1,200.00 - -
3361 - - - 24.00
3362 - 636.66 - 19.17
3363 - 300.00 - 24.00
3364 - 300.00 - 8.00
3365 - 1,050.00 - -
3366 - 1,050.00 - -
The result should look something like this for all ID's:
ID Code Amount Date
3351 10 0 9/12/2014
3351 55 0 9/12/2014
3351 65 0 9/12/2014
3351 85 24 9/12/2014
3356 10 0 9/12/2014
3356 55 1200 9/12/2014
3356 65 0 9/12/2014
3356 85 0 9/12/2014
If you could explain what the macro is doing would also help. Your help is greatly appreciated.
ID 10 55 65 85
3351 - - - 24.00
3356 - 1,200.00 - -
3357 - - - -
3358 - 1,200.00 - -
3360 - 1,200.00 - -
3361 - - - 24.00
3362 - 636.66 - 19.17
3363 - 300.00 - 24.00
3364 - 300.00 - 8.00
3365 - 1,050.00 - -
3366 - 1,050.00 - -
The result should look something like this for all ID's:
ID Code Amount Date
3351 10 0 9/12/2014
3351 55 0 9/12/2014
3351 65 0 9/12/2014
3351 85 24 9/12/2014
3356 10 0 9/12/2014
3356 55 1200 9/12/2014
3356 65 0 9/12/2014
3356 85 0 9/12/2014
If you could explain what the macro is doing would also help. Your help is greatly appreciated.
TrowaD
Posts
2921
Registration date
Sunday September 12, 2010
Status
Moderator
Last seen
December 27, 2022
555
Oct 28, 2014 at 11:55 AM
Oct 28, 2014 at 11:55 AM
So you provide sample data and I write a code for you.
Then you say in doesn't work and provide different sample data.
Of course it doesn't work, macro's are tailored for specific situations.
Taking a look at your new sample, where does the date come from?
Then you say in doesn't work and provide different sample data.
Of course it doesn't work, macro's are tailored for specific situations.
Taking a look at your new sample, where does the date come from?