copy and paste rows in excel to another worksheet vba using input box for the amount of rows to copy

Evie76

New Member
Joined
Jan 17, 2022
Messages
36
Office Version
  1. 365
Platform
  1. Windows
Hi, I'm new to VBA and have been trying to find a code that will transfer data from sheet 1 to sheet 2 using an input box on the amount of rows to copy over.

Sheet 1 is where the user will input the invoice information from D6 to P6, once the information has been checked it would then be copied over to sheet 2 starting in column b and ending in column n. The input box would be used to state how many rows to copy over as the invoices vary. Is there a way for this to be done via VBA. Any help would be greatly appreciated.
 

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
Hi, I'm new to VBA and have been trying to find a code that will transfer data from sheet 1 to sheet 2 using an input box on the amount of rows to copy over.

Sheet 1 is where the user will input the invoice information from D6 to P6, once the information has been checked it would then be copied over to sheet 2 starting in column b and ending in column n. The input box would be used to state how many rows to copy over as the invoices vary. Is there a way for this to be done via VBA. Any help would be greatly appreciated.
Can you attach or describe a bit more. If possible attach file. I think I can help you
 
Upvote 0
Template Invoices - Copy.xlsm
EFGHIJKLMNOP
1LTS InvoiceRate InvoiceSub Value InvLTS SheetRateValue on sheetLTS & Rate Together
20.3264,683£20,698.560
3
4
5Invoice DateBatch NoOriginal RefMeasure_Reference_NumberMeasure_TypeCost_Score_(£)Rate ValueAmount (£)1st line TownPost_CodeNotes
603/06/2021641 - YESSub122UTA6001783UTA7003543Heating_controls_solid1,931£0.32£617.921 Cherry Tree LaneLondonNW33 4QQ
703/06/2021641 - YESSub122UTA6001782UTA7003542B_Broken_solid_nopreHCs10,099£0.32£3,231.682 Cherry Tree LaneLondonNW33 4QQ
803/06/2021641 - YESSub122UTA6001781UTA7003541UFI4,284£0.32£1,370.883 Cherry Tree LaneLondonNW33 4QQ
903/06/2021641 - YESSub122UTA6001777UTA7003540LI_lessequal1001,981£0.32£633.924 Cherry Tree LaneLondonNW33 4QQ
1003/06/2021641 - YESSub122UTA6001778UTA7003539UFI2,178£0.32£696.965 Cherry Tree LaneLondonNW33 4QQ
1103/06/2021641 - YESSub122UTA6001798UTA7003538Compensation_cavity_nopreHCs265£0.32£84.806 Cherry Tree LaneLondonNW33 4QQ
1203/06/2021641 - YESSub122UTA6001797UTA7003537Heating_controls_cavity1,167£0.32£373.447 Cherry Tree LaneLondonNW33 4QQ
1303/06/2021641 - YESSub122UTA6001796UTA7003536B_Broken_cavity_nopreHCs6,061£0.32£1,939.528 Cherry Tree LaneLondonNW33 4QQ
1403/06/2021641 - YESSub122UTA6001795UTA7003535UFI2,178£0.32£696.969 Cherry Tree LaneLondonNW33 4QQ
1503/06/2021655 - YESSub127UTA6001816UTA7003636Compensation_cavity_nopreHCs265£0.32£84.8010 Cherry Tree LaneLondonNW33 4QQ
1603/06/2021655 - YESSub127UTA6001815UTA7003635Heating_controls_cavity1,167£0.32£373.4411 Cherry Tree LaneLondonNW33 4QQ
1703/06/2021655 - YESSub127UTA6001780UTA7003634Smarttherm_cavity_nopreP&RT932£0.32£298.2412 Cherry Tree LaneLondonNW33 4QQ
1803/06/2021655 - YESSub127UTA6001813UTA7003633Compensation_cavity_nopreHCs171£0.32£54.7213 Cherry Tree LaneLondonNW33 4QQ
1903/06/2021655 - YESSub127UTA6001812UTA7003632Heating_controls_cavity692£0.32£221.4414 Cherry Tree LaneLondonNW33 4QQ
2003/06/2021655 - YESSub127UTA6001811UTA7003631B_First_time_CH_cavity6,546£0.32£2,094.7215 Cherry Tree LaneLondonNW33 4QQ
2103/06/2021655 - YESSub127UTA6001823UTA7003630UFI2,398£0.32£767.3616 Cherry Tree LaneLondonNW33 4QQ
2203/06/2021647 - YESSub125UTA6001814UTA7003605B_Broken_cavity_nopreHCs12,123£0.32£3,879.3617 Cherry Tree LaneLondonNW33 4QQ
2303/06/2021647 - YESSub125UTA6001779UTA7003604B_Broken_cavity_nopreHCs10,245£0.32£3,278.4018 Cherry Tree LaneLondonNW33 4QQ
24
25
26
Without
Cell Formulas
RangeFormula
K2,M2K2=SUM(J6:J46)
N2N2=K2*L2
L6:L23L6=J6*K6
Cells with Conditional Formatting
CellConditionCell FormatStop If True
H2,N2Cell ValueduplicatestextNO
H2,M2Cell ValueduplicatestextNO
G2,L2Cell ValueduplicatestextNO
F2,K2Cell ValueduplicatestextNO
Cells with Data Validation
CellAllowCriteria
G2List0.10,0.32
L2List0.10,0.32
P6:P26ListECOHub states measures as being Heating Control


Template Invoices - Copy.xlsm
ABCDEFGHIJKLMN
1InstallerInvoice NoInvoice DateBatch NoOriginal RefOfgem RefMeasure CategoryLTSRate ValueAmountFirst Line of AddressAreaPostcodeNotes
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
Master
 
Upvote 0
Once you enter the number of rows to copy, on which row do you want to start copying?
 
Upvote 0
I meant from which row on the "Without" sheet do you want to start copying? The data starts in Row 6. So if you enter that you want to copy 5 rows rows, do you copy rows 6 to 10?
 
Upvote 0
I meant from which row on the "Without" sheet do you want to start copying? The data starts in Row 6. So if you enter that you want to copy 5 rows rows, do you copy rows 6 to 10?
From row 6 to the row the user has inputted to so it can be 1, 5, 11, etc as the invoices vary on the amount of measures that is on there
 
Upvote 0
Try:
Rich (BB code):
Sub CopyData()
    Application.ScreenUpdating = False
    Dim response As String
    response = InputBox("Please enter the number of rows to copy.")
    If response = "" Then Exit Sub
    Sheets("Without").Range("B6:N6").Resize(response).Copy Sheets("Master").Cells(Sheets("Master").Rows.Count, "B").End(xlUp).Offset(1)
    Application.ScreenUpdating = True
End Sub
Change the sheet names (in red) to suit your needs.
 
Upvote 0
Solution
Try:
Rich (BB code):
Sub CopyData()
    Application.ScreenUpdating = False
    Dim response As String
    response = InputBox("Please enter the number of rows to copy.")
    If response = "" Then Exit Sub
    Sheets("Without").Range("B6:N6").Resize(response).Copy Sheets("Master").Cells(Sheets("Master").Rows.Count, "B").End(xlUp).Offset(1)
    Application.ScreenUpdating = True
End Sub
Change the sheet names (in red) to suit your needs.
This works, however, if I delete the last row in the master sheet when I copy over the next invoice it misses the deleted row, and goes to the next one, if there a way for it not to do that and just copy on the next blank row
 
Upvote 0
This works, however, if I delete the last row in the master sheet when I copy over the next invoice it misses the deleted row, and goes to the next one, if there a way for it not to do that and just copy on the next blank row
I've worked it out. Thank you so much for your help, i really appreciate it :)
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,213
Members
452,618
Latest member
Tam84

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