Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 53
Default Macro - reads cells in a column .If keyword found moves cell conte

Let's say i have a column with lots of cells . Some containt text , some are
empty . Macro should read all the cells . If the given word/character is
found , it moves the content in B column . B column should not have empty
cells

Example :

Keyword : mother

A1 : mother and father
A2 empty cell
A3 : mother
A4 : son
A5 : empty cell
A6 : mother and nice

The results in B column should be :

B1 : mother and father
B2 : mother
B3 : mother and nice


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Macro - reads cells in a column .If keyword found moves cell conte

Hi,

Try this

Sub Versive()
x = 1
lastrow = Cells(Cells.Rows.Count, "A").End(xlUp).Row
Set MyRange = Range("A1:A" & lastrow)
For Each c In MyRange
If InStr(UCase(c.Value), "MOTHER") 0 Then
Cells(x, 2) = c.Value
x = x + 1
End If
Next
End Sub

Mike

"andrei" wrote:

Let's say i have a column with lots of cells . Some containt text , some are
empty . Macro should read all the cells . If the given word/character is
found , it moves the content in B column . B column should not have empty
cells

Example :

Keyword : mother

A1 : mother and father
A2 empty cell
A3 : mother
A4 : son
A5 : empty cell
A6 : mother and nice

The results in B column should be :

B1 : mother and father
B2 : mother
B3 : mother and nice


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 53
Default Macro - reads cells in a column .If keyword found moves cell c

Many thanks , it works !

"Mike H" wrote:

Hi,

Try this

Sub Versive()
x = 1
lastrow = Cells(Cells.Rows.Count, "A").End(xlUp).Row
Set MyRange = Range("A1:A" & lastrow)
For Each c In MyRange
If InStr(UCase(c.Value), "MOTHER") 0 Then
Cells(x, 2) = c.Value
x = x + 1
End If
Next
End Sub

Mike

"andrei" wrote:

Let's say i have a column with lots of cells . Some containt text , some are
empty . Macro should read all the cells . If the given word/character is
found , it moves the content in B column . B column should not have empty
cells

Example :

Keyword : mother

A1 : mother and father
A2 empty cell
A3 : mother
A4 : son
A5 : empty cell
A6 : mother and nice

The results in B column should be :

B1 : mother and father
B2 : mother
B3 : mother and nice


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Macro - reads cells in a column .If keyword found moves cell conte

Instr() has its own comparison parm that you can use to ignore case differences:

If InStr(1, c.Value, "MOTHER", vbtextcompare) 0 Then



Mike H wrote:

Hi,

Try this

Sub Versive()
x = 1
lastrow = Cells(Cells.Rows.Count, "A").End(xlUp).Row
Set MyRange = Range("A1:A" & lastrow)
For Each c In MyRange
If InStr(UCase(c.Value), "MOTHER") 0 Then
Cells(x, 2) = c.Value
x = x + 1
End If
Next
End Sub

Mike

"andrei" wrote:

Let's say i have a column with lots of cells . Some containt text , some are
empty . Macro should read all the cells . If the given word/character is
found , it moves the content in B column . B column should not have empty
cells

Example :

Keyword : mother

A1 : mother and father
A2 empty cell
A3 : mother
A4 : son
A5 : empty cell
A6 : mother and nice

The results in B column should be :

B1 : mother and father
B2 : mother
B3 : mother and nice



--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Macro - reads cells in a column .If keyword found moves cell c

Glad I could help and thanks for the feedback

"andrei" wrote:

Many thanks , it works !

"Mike H" wrote:

Hi,

Try this

Sub Versive()
x = 1
lastrow = Cells(Cells.Rows.Count, "A").End(xlUp).Row
Set MyRange = Range("A1:A" & lastrow)
For Each c In MyRange
If InStr(UCase(c.Value), "MOTHER") 0 Then
Cells(x, 2) = c.Value
x = x + 1
End If
Next
End Sub

Mike

"andrei" wrote:

Let's say i have a column with lots of cells . Some containt text , some are
empty . Macro should read all the cells . If the given word/character is
found , it moves the content in B column . B column should not have empty
cells

Example :

Keyword : mother

A1 : mother and father
A2 empty cell
A3 : mother
A4 : son
A5 : empty cell
A6 : mother and nice

The results in B column should be :

B1 : mother and father
B2 : mother
B3 : mother and nice




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 53
Default Macro - reads cells in a column .If keyword found moves cell c

thanks for the tip

"Dave Peterson" wrote:

Instr() has its own comparison parm that you can use to ignore case differences:

If InStr(1, c.Value, "MOTHER", vbtextcompare) 0 Then



Mike H wrote:

Hi,

Try this

Sub Versive()
x = 1
lastrow = Cells(Cells.Rows.Count, "A").End(xlUp).Row
Set MyRange = Range("A1:A" & lastrow)
For Each c In MyRange
If InStr(UCase(c.Value), "MOTHER") 0 Then
Cells(x, 2) = c.Value
x = x + 1
End If
Next
End Sub

Mike

"andrei" wrote:

Let's say i have a column with lots of cells . Some containt text , some are
empty . Macro should read all the cells . If the given word/character is
found , it moves the content in B column . B column should not have empty
cells

Example :

Keyword : mother

A1 : mother and father
A2 empty cell
A3 : mother
A4 : son
A5 : empty cell
A6 : mother and nice

The results in B column should be :

B1 : mother and father
B2 : mother
B3 : mother and nice



--

Dave Peterson

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
Macro searches for keyword. If found , puts 0 in cell from next co andrei Excel Programming 3 September 29th 09 12:47 PM
Retain cell references when column moves Marlene Charts and Charting in Excel 4 January 10th 09 09:22 PM
Populate a cell based on a keyword it found in another ghobbit Excel Programming 12 May 16th 06 04:47 AM
Populate a cell based on a keyword it found in another ghobbit[_2_] Excel Programming 0 May 11th 06 06:45 PM
Formula to identify a keyword in all cells of a column HTC Excel Discussion (Misc queries) 3 July 28th 05 03:57 PM


All times are GMT +1. The time now is 03:01 AM.

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"