Move full rows for when column C has "any" value to new sheet

emb22

New Member
Joined
Dec 22, 2021
Messages
1
Office Version
  1. 365
Platform
  1. MacOS
Hi all,

Very new to this! Thanks in advance for your help.

Scenario: I have a spreadsheet with 20 columns of info. A, B, and C are the only empty columns that are entered as they are confirmed/completed. The final step is to scan a barcode into column C next to the verified line. Once the barcode is scanned into C, that entire row is copied and pasted into a new sheet. Every row after that is pasted below the previous one on the new sheet (only one new sheet for all confirmed values that are copied and pasted). I found the following code that works if I use same value but because its a barcode and the value is different each time I need a code that will allow me to transfer any value present, nonblank value etc.

Sub MoveBasedOnValue()

Dim xRg As Range

Dim xCell As Range

Dim A As Long

Dim B As Long

Dim C As Long

A = Worksheets("Sheet1").UsedRange.Rows.Count

B = Worksheets("Sheet2").UsedRange.Rows.Count

If B = 1 Then

If Application.WorksheetFunction.CountA(Worksheets("Sheet2").UsedRange) = 0 Then B = 0

End If

Set xRg = Worksheets("Sheet1").Range("C1:C" & A)

On Error Resume Next

Application.ScreenUpdating = False

For C = 1 To xRg.Count

If CStr(xRg(C).Value) = “Empty” Then '

xRg(C).EntireRow.Copy Destination:=Worksheets("Sheet2").Range("A" & B + 1)

xRg(C).EntireRow.Delete

If CStr(xRg(C).Value) = “Empty” Then

C = C - 1

End If

B = B + 1

End If

Next

Application.ScreenUpdating = True
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Maybe this way...
Change sheet name to suit
VBA Code:
Sub MM1()
Dim rng As Range
Set rng = Application.Intersect(ActiveSheet.UsedRange, Range("A:T"))
With Columns("C")
    .AutoFilter field:=1, Criteria1:="<>"
    rng.SpecialCells(xlCellTypeVisible).Copy Sheets("Sheet2").Range("A1")
    .AutoFilter
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,523
Messages
6,120,039
Members
448,940
Latest member
mdusw

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