How to copy multiple lines with a Macro
Closed
Em
-
27 Nov 2015 à 06:33
TrowaD Posts 2921 Registration date Sunday 12 September 2010 Status Contributor Last seen 27 December 2022 - 3 Dec 2015 à 11:35
TrowaD Posts 2921 Registration date Sunday 12 September 2010 Status Contributor Last seen 27 December 2022 - 3 Dec 2015 à 11:35
Related:
- Speedyshare upload
- Excel multiple lines in one cell - Guide
- Sed delete lines - Guide
- Commandos behind enemy lines download - Download - Strategy
- How to split excel sheet into multiple worksheets - Guide
- How to delete multiple files on mac - Guide
2 responses
TrowaD
Posts
2921
Registration date
Sunday 12 September 2010
Status
Contributor
Last seen
27 December 2022
555
30 Nov 2015 à 11:07
30 Nov 2015 à 11:07
So now we are past Sunday, I guess this question isn't relevant anymore ...
TrowaD
Posts
2921
Registration date
Sunday 12 September 2010
Status
Contributor
Last seen
27 December 2022
555
3 Dec 2015 à 11:35
3 Dec 2015 à 11:35
Hi Em,
Hopefully you made a mistake in your sample data: On sheet2 the year is adjusted for country A and B but not for C. In the code provided the year is also adjusted for country C.
Here are the codes:
And
And here is your workbook with codes:
http://speedy.sh/Sw5GU/Em-Hot-to-copy.xlsm
Did this help you out?
Best regards,
Trowa
Hopefully you made a mistake in your sample data: On sheet2 the year is adjusted for country A and B but not for C. In the code provided the year is also adjusted for country C.
Here are the codes:
Private Sub CommandButton1_Click()
Dim mCountry As String
Dim x, y As Long
mCountry = InputBox("Please input the Country you wish to add:")
If mCountry = vbNullString Then Exit Sub
Range("A1").End(xlDown).Offset(1, 0).Insert
Range("A1").End(xlDown).Offset(1, 0) = mCountry
Sheets("Sheet2").Range("A2:E21").Copy Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
x = Sheets("Sheet2").Range("C" & Rows.Count).End(xlUp).Row
For y = x To x - 19 Step -1
Sheets("Sheet2").Cells(y, "C") = mCountry
Next y
End Sub
And
Private Sub CommandButton2_Click()
Dim mYear, cRows As Integer
Dim x, y As Long
mYear = InputBox("Please input the Year you wish to add:")
If mYear = vbNullString Then Exit Sub
Range("A1").End(xlDown).End(xlDown).End(xlDown).Offset(1, 0).Insert
Range("A1").End(xlDown).End(xlDown).End(xlDown).Offset(1, 0) = mYear
cRows = Sheets("Sheet2").Cells(Rows.Count, "A").End(xlUp).Row + 1
Sheets("Sheet2").Range("A2:E" & Sheets("Sheet2").Cells(Rows.Count, "A").End(xlUp).Row).Copy Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
x = Sheets("Sheet2").Range("D" & Rows.Count).End(xlUp).Row
For y = x To cRows Step -1
Sheets("Sheet2").Cells(y, "D") = mYear
Next y
End Sub
And here is your workbook with codes:
http://speedy.sh/Sw5GU/Em-Hot-to-copy.xlsm
Did this help you out?
Best regards,
Trowa
30 Nov 2015 à 13:25
Thanks in advance!
1 Dec 2015 à 11:04
So you have a database in Sheet 2. Does Sheet 1 look the same?
Do you enter a country/year in Sheet 1 and then you want to look up all the matching data from Sheet 2?
I'm actually completely lost as to what you are trying to achieve.
Consider the option to upload your workbook to a free file sharing site like www.speedyshare.com or ge.tt and post back the download link.
Make sure you show how it is now and how you want it to be.