adding new line vba code

Patriot2879

Well-known Member
Joined
Feb 1, 2018
Messages
1,259
Office Version
  1. 2010
Platform
  1. Windows
HI I am very new to VBA and i have done the code below where it transfers selected cells into another sheet into cells i have designated from a 'add' button, what i cant do is automatically add a new line when the 'add' button has been clicked on.

Pleased can you help with the code below so it will auto goto new line when add button is clicked

Private Sub CommandButton2_Click()

Application.ScreenUpdating = False




Sheets("Northants").Range("B22:B22").Copy
Sheets("Sheet2").Activate
Sheets("Sheet2").Range("A2:A2").Select
ActiveSheet.Paste

Sheets("Northants").Range("B23:B23").Copy
Sheets("Sheet2").Activate
Sheets("Sheet2").Range("B2:B2").Select
ActiveSheet.Paste

Sheets("Northants").Range("B24:B24").Copy
Sheets("Sheet2").Activate
Sheets("Sheet2").Range("C2:C2").Select
ActiveSheet.Paste

Sheets("Northants").Range("B25:B25").Copy
Sheets("Sheet2").Activate
Sheets("Sheet2").Range("D2:D2").Select
ActiveSheet.Paste

Sheets("Northants").Range("B26:B26").Copy
Sheets("Sheet2").Activate
Sheets("Sheet2").Range("E2:E2").Select
ActiveSheet.Paste

Sheets("Northants").Range("B27:B27").Copy
Sheets("Sheet2").Activate
Sheets("Sheet2").Range("F2:F2").Select
ActiveSheet.Paste

Sheets("Northants").Range("B28:B28").Copy
Sheets("Sheet2").Activate
Sheets("Sheet2").Range("G2:G2").Select
ActiveSheet.Paste

Sheets("Northants").Range("B29:B29").Copy
Sheets("Sheet2").Activate
Sheets("Sheet2").Range("H2:H2").Select
ActiveSheet.Paste

Sheets("Northants").Range("C29:C29").Copy
Sheets("Sheet2").Activate
Sheets("Sheet2").Range("I2:I2").Select
ActiveSheet.Paste

Sheets("Northants").Range("B30:B30").Copy
Sheets("Sheet2").Activate
Sheets("Sheet2").Range("J2:J2").Select
ActiveSheet.Paste

Sheets("Northants").Range("B31:B31").Copy
Sheets("Sheet2").Activate
Sheets("Sheet2").Range("K2:K2").Select
ActiveSheet.Paste

Application.CutCopyMode = False

Application.ScreenUpdating = True
End Sub
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Hi & welcome to MrExcel
Are you copying values only?
 
Last edited:
Upvote 0
If it is values only try
Code:
Private Sub CommandButton2_Click()
   
   Dim NxtRw As Long
Application.ScreenUpdating = False

   NxtRw = Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1).Row
   With Sheets("Postcodes")
      Sheets("Sheet2").Range("A" & NxtRw).Resize(, 8).Value = Application.Transpose(.Range("B22:B29").Value)
      Sheets("Sheet2").Range("I" & NxtRw).Value = .Range("C29").Value
      Sheets("Sheet2").Range("J" & NxtRw).Resize(, 2).Value = Application.Transpose(.Range("B30:B31").Value)
   End With

Application.ScreenUpdating = True
End Sub
 
Upvote 0
that worked lovely thank you so much for your help much apprecaited, i am really new to vba but loving the coding, bit tricky in parts and this has had me stuck for over a week and yuo have resolved it near enough instantly thank you again :) :)
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,875
Members
452,363
Latest member
merico17

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