View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Jacob Skaria Jacob Skaria is offline
external usenet poster
 
Posts: 8,520
Default Copy entire row(s) to another workbook based on partial cell crite

Try the below macro from Main xls activesheet

Sub Macro()

Dim wb As Workbook, lngRow As Long, lngNextRow As Long
Set wb = Workbooks("after.xls")

For lngRow = 1 To ActiveSheet.Cells(Rows.Count, "I").End(xlUp).Row
If Range("I" & lngRow) Like "TML*" Or Range("I" & lngRow) Like "FTF*" Then
lngNextRow = wb.Worksheets(CStr(Left(Range("I" & lngRow), 3))).Cells( _
Rows.Count, "I").End(xlUp).Row + 1
Rows(lngRow).Copy _
wb.Worksheets(CStr(Left(Range("I" & lngRow), 3))).Rows(lngNextRow)
End If
Next

End Sub


If this post helps click Yes
---------------
Jacob Skaria


"Nik" wrote:

Hi

I am looking for VB codes to copy rows based on partial cell content.

I have a spreadsheet called "main.xls" from which I would like to copy data
to another spreadsheet when certain crietria are met.

Column I have following data.
TML123
TML702
TML4568
TML956
FTF987
FTF0956
FTF687
TML257

I would like the macro to copy rows that have TML prefix to another workbook
(After.xls) and paste under a tab named TML. The macro should also copy rows
that have FTF prefix to the same workbook (After.xls) and paste under a tab
named FTF.

Thanks