vba help - Seperate data

Mallesh23

Well-known Member
Joined
Feb 4, 2009
Messages
976
Office Version
  1. 2010
Platform
  1. Windows
Hi Team,

Need vba help, I want to seperate my data where Cell contain "No Record"

My Dummy Data is in Column ("A:E").
Expected Output is in Column ("H:L").

Book1
ABCDEFGHIJKL
1InvoiceProductAmountProduct CodeSales ManInvoiceProductAmountProduct CodeSales Man
238692No Record40000Sachin38692No Record40000Sachin
345262Lux8000020No Record45262Lux8000020No Record
423009Lux8000030Sachin52367LifebuoyNo Record20Dhoni
552367LifebuoyNo Record20Dhoni59622Lux40000No RecordDhoni
653249Lux8000030Kohli21013Lux80000No RecordKohli
759622Lux40000No RecordDhoni22225Lifebuoy4000030No Record
821013Lux80000No RecordKohli32752No RecordNo Record30Sachin
923701Lux8000020Dhoni48084No Record8000020Dhoni
1022225Lifebuoy4000030No Record24972LifebuoyNo Record20Kohli
1148318Lux4000020Dhoni55267Lux40000No RecordKohli
1232752No RecordNo Record30Sachin55387No Record8000020Sachin
1348084No Record8000020Dhoni52272LifebuoyNo Record30Dhoni
1435559Lux4000030SachinNo RecordLifebuoy8000030Kohli
1524972LifebuoyNo Record20Kohli57887No Record8000030Kohli
1628817Lux8000030Dhoni47973No Record8000030Dhoni
1721308Lux4000020Sachin57619Lux40000No RecordDhoni
1839018Lifebuoy4000030Kohli
1922946Lux4000020Dhoni
2057604Lifebuoy8000030Dhoni
2121541Lifebuoy8000030Dhoni
2255267Lux40000No RecordKohli
2354834Lifebuoy8000020Sachin
2453374Lux4000030Kohli
2555387No Record8000020Sachin
2643203Lifebuoy4000030Dhoni
2759984Lifebuoy4000020Dhoni
2852272LifebuoyNo Record30Dhoni
2935336Lifebuoy4000020Sachin
30No RecordLifebuoy8000030Kohli
3151272Lux8000020Dhoni
3257887No Record8000030Kohli
3347973No Record8000030Dhoni
3429859Lifebuoy4000030Kohli
3557619Lux40000No RecordDhoni
Sheet1


Thanks
mg
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Hi Try Below code

VBA Code:
Option Explicit
Sub Seprate_Data()
Dim lr As Long
Dim i As Integer
Dim rng As Range
Dim Pasterow As Integer
Pasterow = 2
lr = Range("A" & Rows.Count).End(xlUp).Row
For i = 2 To lr
    Set rng = Range(Cells(i, 1), Cells(i, 5))
    If Application.WorksheetFunction.CountIf(rng, "No Record") > 0 Then
        rng.Copy Range("H" & Pasterow)
        Pasterow = Pasterow + 1
    End If
Next
Range("A1:E1").Copy Range("H1")
End Sub
 
Upvote 0
Another option
VBA Code:
Sub Mallesh()
   Dim Ary As Variant, Nary As Variant
   Dim r As Long, c As Long, cc As Long, nr As Long
   
   Ary = Range("A1").CurrentRegion.Value2
   ReDim Nary(1 To UBound(Ary), 1 To UBound(Ary, 2))
   
   For r = 2 To UBound(Ary)
      For c = 1 To UBound(Ary, 2)
         If Ary(r, c) = "No Record" Then
            nr = nr + 1
            For cc = 1 To UBound(Ary, 2)
               Nary(nr, cc) = Ary(r, cc)
            Next cc
            Exit For
         End If
      Next c
   Next r
   Range("H2").Resize(nr, UBound(Nary, 2)).Value = Nary
End Sub
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,958
Messages
6,122,475
Members
449,087
Latest member
RExcelSearch

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