Hi, I have a code that copy data from sheet "from" to sheet "Sheet1" and after the data was copied and pasted, there will be additional columns next to the data pasted that need user to input the year.
For this the VBA code will prompt a INPUT BOX for user to input the value, then return the value to column K
But the code I'm using only paste the YEAR input by user at the first row before the pasted data.
For this the VBA code will prompt a INPUT BOX for user to input the value, then return the value to column K
But the code I'm using only paste the YEAR input by user at the first row before the pasted data.
VBA Code:
Sub inputbox1()
Dim nextrow As Long, year As Long, lastrow As Long
lastrow = Sheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Row
With Sheets("from")
.Range("A9", .Range("A9").End(xlDown).End(xlToRight)).Copy
End With
With Sheets("Sheet1").ListObjects(1).Range
If .SpecialCells(xlConstants).Count = .Columns.Count Then
nextrow = 2
Else
nextrow = .Rows.Count + 1
End If
.Cells(nextrow, 1).PasteSpecial xlValues
year = InputBox("Enter year.")
.Range("K" & lastrow).Value = year
End With
Application.CutCopyMode = False
End Sub
Book3(AutoRecovered).xlsx | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | H | I | J | K | L | |||
1 | Order ID | Ship Date | Order Date | Ship Mode | Customer ID | Customer Name | Destination | Contact Number | Status | Segment | Year | Month | ||
2 | CA-2014-105893 | 11/18/2014 | 11/11/2014 | Standard Class | PK-19075 | Pete Kriz | New York | 123456 | On the Way | Consumer | 2019 | |||
3 | CA-2014-167164 | 5/15/2014 | 5/13/2014 | Second Class | AG-10270 | Alejandro Grove | Washington | 123456 | Failed | Consumer | ||||
4 | CA-2014-143336 | 9/1/2014 | 8/27/2014 | Second Class | ZD-21925 | Zuschuss Donatelli | New Zealand | 123456 | Delivered | Consumer | ||||
5 | CA-2014-143336 | 9/1/2014 | 8/27/2014 | Second Class | ZD-21925 | Zuschuss Donatelli | New York | 123456 | On the Way | Consumer | ||||
6 | CA-2014-143336 | 9/1/2014 | 8/27/2014 | Second Class | ZD-21925 | Zuschuss Donatelli | Washington | 123456 | Delivered | Consumer | ||||
7 | CA-2016-137330 | 12/13/2016 | 12/9/2016 | Standard Class | KB-16585 | Ken Black | Japan | 123456 | On the Way | Corporate | ||||
8 | CA-2016-137330 | 12/13/2016 | 12/9/2016 | Standard Class | KB-16585 | Ken Black | New York | 123456 | Delivered | Corporate | ||||
9 | US-2017-156909 | 7/18/2017 | 7/16/2017 | Second Class | SF-20065 | Sandra Flanagan | Washington | 123456 | On the Way | Consumer | ||||
10 | CA-2015-106320 | 9/30/2015 | 9/25/2015 | Standard Class | EB-13870 | Emily Burns | New Zealand | 123456 | On the Way | Consumer | ||||
11 | CA-2016-121755 | 1/20/2016 | 1/16/2016 | Second Class | EH-13945 | Eric Hoffmann | New York | 123456 | Failed | Consumer | ||||
12 | CA-2016-121755 | 1/20/2016 | 1/16/2016 | Second Class | EH-13945 | Eric Hoffmann | Washington | 123456 | On the Way | Consumer | ||||
13 | US-2015-150630 | 9/21/2015 | 9/17/2015 | Standard Class | TB-21520 | Tracy Blumstein | New Zealand | 123456 | Delivered | Consumer | ||||
14 | US-2015-150630 | 9/21/2015 | 9/17/2015 | Standard Class | TB-21520 | Tracy Blumstein | New York | 123456 | On the Way | Consumer | ||||
15 | US-2015-150630 | 9/21/2015 | 9/17/2015 | Standard Class | TB-21520 | Tracy Blumstein | Washington | 123456 | Delivered | Consumer | ||||
Sheet1 |