VB Help with code to copy selected rows to specified cells in another sheet.

Excel_Assis

Board Regular
Joined
Feb 19, 2011
Messages
132
Office Version
  1. 2016
Platform
  1. Windows
Hi
Could I please ask help from someone with VB code.
The VB below should by clicking in the cell column H next to the row of data needed then copy the data to a another sheet at this point it is sheet6 at a specified start cell. There are several source sheets and the selected data from these sheets needs to be copied to sheet6 at a specified starting cell.

At present when the cell is clicked the tick font is made visible meaning the row selected and then viewing the destination sheet. only the first cell of data from source sheet is shown and if two rows are selected from source sheet only the last selected row first cell is shown. Meaning the copy overwrites the previous and does not increment by one row.





Source Sheet = Cost1

B C D E F G H

Cost1Select Required
DescriptionTypeMin # of UnitsCost/UnitTotal
unit 1Unit 1 type2$ 30.00$ 60.00a
unit 2Unit 2 type0$ 5.00$ -
unit 3Unit 3 type3$ 20.00$ 60.00a
unit 4Unit 4 type0$ 5.00$ -
unit 5Unit 5 type0$ 10.00$ -
Total$ 120.00

Select and Copy Code


Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Target.Cells.Count > 1 Then Exit Sub
If Not Intersect(Target, Range("H8:H12")) Is Nothing Then
Target.Font.Name = "Marlett"
If Target = vbNullString Then
Target = "a"
Else
Target = vbNullString
End If
End If


'/// Below code will copy Selected items to sheet6

'Copy Items to sheet6 and start at selected cell and incrament by 1 row.
If Not Intersect(Target, Range("H8:H12")) Is Nothing Then
Select Case Target.Value
Case "a"
Cells(Target.Row, 1).Copy Destination:=Sheet6.Range("D10").End(xlUp).Offset(1, 0)
End Select
End If

End Sub

[/CODE]
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Try. Change this line
VBA Code:
Cells(Target.Row, 1).Copy Destination:=Sheet6.Range("D10").End(xlUp).Offset(1, 0)
as
VBA Code:
Cells(Target.Row, 1).Copy Destination:=Sheet6.Range("D"  & rows.count).End(xlUp).Offset(1, 0)
 
Upvote 0
Try. Change this line
VBA Code:
Cells(Target.Row, 1).Copy Destination:=Sheet6.Range("D10").End(xlUp).Offset(1, 0)
as
VBA Code:
Cells(Target.Row, 1).Copy Destination:=Sheet6.Range("D"  & rows.count).End(xlUp).Offset(1, 0)
Hi I thank you for your reply however it does not work dew to the cell a D is a merged cell. This is row 1, The destination cell must start at D10 to G10 and then Auto increment to D11 to G11 then auto increment to D12 to G12 and so on.
 
Upvote 0
The following is what happens on the destination sheet6.


Inventory_Xfer (1).xls
DEFGH
9DescriptionTypeUnitCostTOTAL
10unit 3$0.00
11$0.00
12$0.00
13$0.00
14$0.00
15$0.00
16$0.00
17$0.00
18$0.00
19$0.00
20TOTAL$0.00
Sys_Ser_Quote
Cell Formulas
RangeFormula
H10:H19H10=F10*G10
H20H20=SUM(H10:H19)





Following is the Source sheet10.
Inventory_Xfer (1).xls
ABCDEFH
5Cost1Select Required
6
7DescriptionTypeMin # of UnitsCost/UnitTotalSelect Required
8
9unit 1Unit 1 type2$ 30.00$ 60.00
10unit 2Unit 2 type0$ 5.00$ -
11unit 3Unit 3 type3$ 20.00$ 60.00a
12unit 4Unit 4 type0$ 5.00$ -a
13unit 5Unit 5 type0$ 10.00$ -
14 Total $ 120.00
Cost_1
Cell Formulas
RangeFormula
F9:F13F9=SUM(C9*E9)
F14F14=SUM(F9:F13)
 
Upvote 0
Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at: VB Help with code to copy selected rows to specified cells in another sheet.
There is no need to repeat the link(s) provided above but if you have posted the question at other places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0
I don't understand what you want.
Try.
VBA Code:
selection.resize(1,4).Copy Destination:=Sheet6.Range("D"  & rows.count).End(xlUp).Offset(1, 0)
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,173
Members
453,021
Latest member
Justyna P

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