mohamadba91

New Member
Joined
Aug 14, 2019
Messages
6
hi
i want a code which check second colulm and if to right charcter was 01 then copy entire row to another sheet
for example if b2=9164801 then copy row 2 in sheet2 and do it again until the last row
can anybody help me on it
i would appreciate you
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Does this do what you want? Change destination sheet name to suit - assumes destination sheet already exists.
Code:
Sub CopyIf01()
Dim c As Range, NxRw As Long
Application.ScreenUpdating = False
For Each c In Range("B1:B" & Cells(Rows.Count, "B").End(xlUp).Row)
    If c.Value Like "*01" Then
       With Sheets("Sheet3")
            If IsEmpty(.Range("A1")) Then
                NxRw = 1
            Else
                NxRw = .Cells(Rows.Count, "A").End(xlUp).Row + 1
            End If
        End With
        Intersect(c.EntireRow, ActiveSheet.UsedRange).Copy Destination:=Sheets("Sheet3").Cells(NxRw, "A")
    End If
Next c
With Application
    .CutCopyMode = False
    .ScreenUpdating = True
End With
 
Upvote 0
Hi,
Check this out.

Code:
Sub CopyRows()
Dim ws1 as worksheet
Dim ws2 ad worksheet
Dim i&
Dim counter&

Set ws1=worksheets(1)
Set ws2=worksheets(2)
i=2
With ws1
Do while .cells(i, "B")<>""
    If cstr(right(.cells(i,"B"),2))="01" then
         counter=counter+1
        .cells(i,"B").EntireRow.copy ws2.cells(counter,"A")
    End if
    i=i+1
Loop
end with

Set ws1=nothing
Set ws2= nothing
End sub
 
Upvote 0

Forum statistics

Threads
1,213,554
Messages
6,114,280
Members
448,562
Latest member
Flashbond

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