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

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
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)
Hi thank you for your reply after making your suggested changes only the two ticks are copied to sheet2 D2:D3. Images attached.

Source Sheet1

Sheet1 data copy sheet2 sample.xlsm
ABCDEFGHI
3
4
5Cost1Select Required
6
7DescriptionTypeMin # of UnitsCost/UnitTotalSelect Required
8
9unit 1Unit 1 type2$ 30.00$ 60.00a
10unit 2Unit 2 type0$ 5.00$ -
11unit 3Unit 3 type3$ 20.00$ 60.00a
12unit 4Unit 4 type0$ 5.00$ -
13unit 5Unit 5 type0$ 10.00$ -
14 Total $ 120.00
15
16
17
18
Sheet1
Cell Formulas
RangeFormula
F9:F13F9=SUM(C9*E9)
F14F14=SUM(F9:F13)




Destination Sheet2

Sheet1 data copy sheet2 sample.xlsm
ABCDEFGHIJ
1
2a
3a
4
5
6
7
8
9
1060.00
1160.00
120.00
130.00
140.00
150.00
160.00
170.00
180.00
190.00
20TOTAL$120.00
21
22
Sheet2
Cell Formulas
RangeFormula
H12:H19H12=F12*G12
H20H20=SUM(H10:H19)



Destination sheet2 should look like the following I manually edited it to show what the result should look like.

Sheet1 data copy sheet2 sample.xlsm
ABCDEFGHIJ
1
2
3
4
5
6
7
8
9
10unit1unit 1 type2$30.0060.00
11unit3unit 3 type3$20.0060.00
120.00
130.00
140.00
150.00
160.00
170.00
180.00
190.00
20TOTAL$120.00
21
22
Sheet2
Cell Formulas
RangeFormula
H12:H19H12=F12*G12
H20H20=SUM(H10:H19)
 
Upvote 0

Forum statistics

Threads
1,223,889
Messages
6,175,223
Members
452,620
Latest member
dsubash

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