Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Macro to cut rows into another worksheet if a cell contains a specific word

Ive got a spreadsheet which contains outstanding share trades which clients
have placed, but it contains other products i do not deal with. I would
like the macro to run throught the asset name column and to cut the entire
row into another worksheet called delete if it contains either of the
following: SWAPS, FX, CFD,Bank Bill,pension or SUPER. Would this code be
straight forward to write? anyone with suggestions?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default Macro to cut rows into another worksheet if a cell contains a spec

Sub Remover()
Dim newrow As Long
Dim rw As Long
Dim product As String
product = "A"
rw = 1
Do Until Cells(rw, product) = ""
Select Case Cells(rw, product)
Case "SWAPS", "FX", "CFD", "Bank Bill", "pension", "SUPER"
newrow = newrow + 1
Worksheets("delete").Rows(newrow).Value = Rows(rw).Value
Case Else
End Select
rw = rw + 1
Loop
End Sub

"Jason via OfficeKB.com" wrote:

Ive got a spreadsheet which contains outstanding share trades which clients
have placed, but it contains other products i do not deal with. I would
like the macro to run throught the asset name column and to cut the entire
row into another worksheet called delete if it contains either of the
following: SWAPS, FX, CFD,Bank Bill,pension or SUPER. Would this code be
straight forward to write? anyone with suggestions?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Macro to cut rows into another worksheet if a cell contains a specific word

Assume assests column is F:

Sub CutData()
Dim sStr as String, Cell as Range, rng as Range
sStr = "#SWAPS#FX#CFD#Bank Bill#Pension#SUPER#"
for each cell in Range("F2:F200")
if Instr(1,sStr,Cell.Value,vbTextCompare)0 then
if rng is nothing then
set rng = cell
else
set rng = union(rng,cell)
end if
end if
Next
if not rng is nothing then
rng.EntireRow.copy Destination:=worksheets( _
"OtherSheet").Range("A1")
rng.EntireRow.Delete
End if
End Sub

--
Regrds,
Tom Ogilvy

"Jason via OfficeKB.com" wrote in message
...
Ive got a spreadsheet which contains outstanding share trades which

clients
have placed, but it contains other products i do not deal with. I would
like the macro to run throught the asset name column and to cut the entire
row into another worksheet called delete if it contains either of the
following: SWAPS, FX, CFD,Bank Bill,pension or SUPER. Would this code be
straight forward to write? anyone with suggestions?



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 147
Default Macro to cut rows into another worksheet if a cell contains a specific word

Try something like this You will need to change the variables below to match
tour rows and sheet names etc.


Public Sub CleanUp_My_Data()

Dim Rng As Range 'number of rows
Dim First_Row As Integer 'FIRST ROW Number
Dim SheetName As String 'Name of working SHEET
Dim Paste_Sheet As String 'Name of sheet to Paste to
Dim Column_To_Check As String 'Letter of the asset name column
Dim Paste_Row As Integer
Dim lngROW As Long 'row count


'ADJUST THESE VALUES BELOW

First_Row = 5
SheetName = "Sheet1"
Paste_Sheet = "delete"
Column_To_Check = "B" 'What is the AssetName Column
Paste_Row = 1

'--------------------------------------------------------------------------------------------------
'--------------------------------------------------------------------------------------------------
Set Rng = Worksheets(SheetName).UsedRange.Rows
lngROW = First_Row


While lngROW <= Rng.Rows.Count


If InStr(1, UCase(Worksheets(SheetName).Range("F" & lngROW).Value),
"SWAPS") 0 Or _
InStr(1, UCase(Worksheets(SheetName).Range("F" & lngROW).Value),
"FX") 0 Or _
InStr(1, UCase(Worksheets(SheetName).Range("F" & lngROW).Value),
"CFD") 0 Or _
InStr(1, UCase(Worksheets(SheetName).Range("F" & lngROW).Value),
"BANK BILL") 0 Or _
InStr(1, UCase(Worksheets(SheetName).Range("F" & lngROW).Value),
"PENSION") 0 Or _
InStr(1, UCase(Worksheets(SheetName).Range("F" & lngROW).Value),
"SUPER") 0 Then

Application.Range("A" & lngROW, "ZZ" & lngROW).Copy
Destination:=Worksheets(Paste_Sheet).Range("A" & Paste_Row)

lngROW = lngROW + 1
Paste_Row = Paste_Row + 1
End If


DoEvents
Wend


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Macro to cut rows into another worksheet if a cell contains a specific word

Thanks guys for your input ! ill give it a crack when I go to work on
monday. Enjoy your weekend !

Jason

--
Message posted via http://www.officekb.com
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Link from a specific Cell in Excel to a specific para. in Word CathyK Excel Worksheet Functions 0 August 10th 06 04:40 PM
Hiding rows if specific cell does not contain key word jermsalerms Excel Worksheet Functions 1 June 22nd 06 06:10 PM
Open a specific Word document from an Excel Macro Canoeist Excel Programming 3 March 22nd 05 06:35 AM
delete row contains specific word in an macro Jean-Francois Excel Discussion (Misc queries) 4 January 11th 05 11:40 PM
Macro to search a column for a specific word and replace with wendy Excel Programming 5 January 19th 04 05:41 PM


All times are GMT +1. The time now is 07:16 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"