Insert value from input box to the blank cell in a column

Status
Not open for further replies.

ChanL

Board Regular
Joined
Apr 8, 2021
Messages
65
Office Version
  1. 2019
Platform
  1. Windows
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.
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
ABCDEFGHIJKL
1Order IDShip DateOrder DateShip ModeCustomer IDCustomer NameDestinationContact NumberStatusSegmentYearMonth
2CA-2014-10589311/18/201411/11/2014Standard ClassPK-19075Pete KrizNew York123456On the WayConsumer2019
3CA-2014-1671645/15/20145/13/2014Second ClassAG-10270Alejandro GroveWashington123456FailedConsumer
4CA-2014-1433369/1/20148/27/2014Second ClassZD-21925Zuschuss DonatelliNew Zealand123456DeliveredConsumer
5CA-2014-1433369/1/20148/27/2014Second ClassZD-21925Zuschuss DonatelliNew York123456On the WayConsumer
6CA-2014-1433369/1/20148/27/2014Second ClassZD-21925Zuschuss DonatelliWashington123456DeliveredConsumer
7CA-2016-13733012/13/201612/9/2016Standard ClassKB-16585Ken BlackJapan123456On the WayCorporate
8CA-2016-13733012/13/201612/9/2016Standard ClassKB-16585Ken BlackNew York123456DeliveredCorporate
9US-2017-1569097/18/20177/16/2017Second ClassSF-20065Sandra FlanaganWashington123456On the WayConsumer
10CA-2015-1063209/30/20159/25/2015Standard ClassEB-13870Emily BurnsNew Zealand123456On the WayConsumer
11CA-2016-1217551/20/20161/16/2016Second ClassEH-13945Eric HoffmannNew York123456FailedConsumer
12CA-2016-1217551/20/20161/16/2016Second ClassEH-13945Eric HoffmannWashington123456On the WayConsumer
13US-2015-1506309/21/20159/17/2015Standard ClassTB-21520Tracy BlumsteinNew Zealand123456DeliveredConsumer
14US-2015-1506309/21/20159/17/2015Standard ClassTB-21520Tracy BlumsteinNew York123456On the WayConsumer
15US-2015-1506309/21/20159/17/2015Standard ClassTB-21520Tracy BlumsteinWashington123456DeliveredConsumer
Sheet1
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
How about
VBA Code:
Sub inputbox1()

Dim nextrow As Long, year As Long, lastrow As Long


With Sheets("from")
  With .Range("A9", .Range("A9").End(xlDown).End(xlToRight))
      lastrow = .Rows.Count
      .Copy
   End With
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" & nextrow).Resize(lastrow).Value = year


End With


Application.CutCopyMode = False

End Sub
 
Upvote 0
Duplicate to: Input data at blank row at certain columns

In future, please do not post the same question multiple times. Per Forum Rules (#12), posts of a duplicate nature will be locked or deleted.

In relation to your question here, I have closed this thread so please continue in the linked thread.
 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,214,579
Messages
6,120,365
Members
448,956
Latest member
Adamsxl

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