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

Status
Not open for further replies.

ChanL

New Member
Joined
Apr 8, 2021
Messages
45
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

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
65,596
Office Version
  1. 365
Platform
  1. Windows
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
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
65,596
Office Version
  1. 365
Platform
  1. Windows
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.
 
Status
Not open for further replies.

Forum statistics

Threads
1,147,517
Messages
5,741,627
Members
423,674
Latest member
Charles2dodo

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
Top