Transfer specific rows that contain data

Gemsie

New Member
Joined
Sep 26, 2013
Messages
5
I have a file that is set up as a pricing list. Column 10 is the one where quantities are written own and it automatically calculates the price.

However, is there a way of only transferring those rows which have had products selected onto a second worksheet, in order to make a "summary invoice"?

I'll be honest, I'm a complete amateur at VBA so tried the following after attempting to edit someone else's code, but it's not working.


Code:
Sub RemoveErrors()

Application.ScreenUpdating = False

Dim LastRow As Long
Dim BadRow As Range

LastRow = Cells(Rows.Count, "G").End(xlUp).Row

Sheets("Sheet1").Select
Range("G3" & LastRow).Select
For Each BadRow In Range("G3" & LastRow)

Select Case BadRow.Value

Case "1"
BadRow.EntireRow.Select
Selection.Cut
Sheets("Sheet2").Select
Range("A" & Rows.Count).End(xlUp).Offset(1).Select
ActiveSheet.Paste

Case "2"
BadRow.EntireRow.Select
Selection.Cut
Sheets("Sheet2").Select
Range("A" & Rows.Count).End(xlUp).Offset(1).Select
ActiveSheet.Paste

End Select

Next BadRow

End Sub
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Okay, I've tried again and I think it works?!

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim i, LastRow

LastRow = Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row
Sheets("Sheet2").Range("A2:I500").ClearContents
For i = 2 To LastRow
If Sheets("Sheet1").Cells(i, "G").Value = "1" Then
Sheets("Sheet1").Cells(i, "G").EntireRow.Copy Destination:=Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1)
End If
Next i


End Sub

Not entirely sure if I can change it to reflect people buying multiples of things though...


EDIT: Yep, have no idea how to add multiples!
 
Last edited:
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,208
Members
448,554
Latest member
Gleisner2

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