Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default Search Cells

hello,

I am writing a macro in which I would like to search column A (which is a
long string) and see if it contains a word in there somewhere. If it does
then I would like column F to return the number in column C as a positive
number and if it does not then return the number in colum C as a negative
number.

thanks,
H
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Search Cells

Hi H,

Try something like:

'================
Public Sub Tester001()
Dim WB As Workbook
Dim SH As Worksheet
Dim rng As Range
Dim rcell As Range
Dim LRow As Long
Const sStr As String = "Fox" '<<===== CHANGE

Set WB = ActiveWorkbook '<<===== CHANGE
Set SH = WB.Sheets("Sheet1") '<<===== CHANGE

LRow = Cells(Rows.Count, "A").End(xlUp).Row

Set rng = SH.Range("A1:A" & LRow)

For Each rcell In rng.Cells
With rcell
If InStr(1, .Value, sStr, vbTextCompare) Then
.Offset(0, 5) = .Offset(0, 2)
Else
.Offset(0, 5) = .Offset(0, 2) * -1
End If
End With
Next rcell

End Sub
'<<================


---
Regards,
Norman



"hfazal" wrote in message
...
hello,

I am writing a macro in which I would like to search column A (which is a
long string) and see if it contains a word in there somewhere. If it does
then I would like column F to return the number in column C as a positive
number and if it does not then return the number in colum C as a negative
number.

thanks,
H



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
protect cells in excel, but also allow a search in those cells? LindaAlex Excel Worksheet Functions 2 January 28th 10 02:51 PM
search within a range of cells? [email protected] Excel Discussion (Misc queries) 2 April 22nd 07 08:08 AM
Search cells on a page? Josh Orfanakis Excel Programming 0 December 23rd 05 04:46 PM
Search Cells kwedde01[_3_] Excel Programming 0 June 29th 05 05:09 PM
Search a column for the last five cells? Daniel[_10_] Excel Programming 3 April 26th 04 04:38 PM


All times are GMT +1. The time now is 12:44 AM.

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

About Us

"It's about Microsoft Excel"