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

Can you please help me with some code:

If in columns 1-3000, there is a sentence with "INC" in
it, then in column 2 the word "CORP" should appear.

If in columns 1-3000, there is a sentence with "SOCIETY"
in it, then in column 2 the word "ASSC/FNDN" should appear.

If in columns 1-3000, there is a sentence
with "FOUNDATION" in it, then in column 2 the
word "ASSC/FNDN" should appear.

If in columns 1-3000, there is a sentence
with "UNIVERSITY" in it, then in column 2 the word "ACAD"
should appear.

Thanks. DaveB
  #2   Report Post  
Posted to microsoft.public.excel.programming
Art Art is offline
external usenet poster
 
Posts: 587
Default Simple Code Help

DaveB,

Try this:

Sub temp()
Dim i As Integer
Dim t As String

Sheets("Sheet1").Activate
For i = 1 To 3000
t = Cells(i, 1).Value
If InStr(1, t, " INC", vbTextCompare) 0 Then
Cells(i, 2) = "CORP"
ElseIf InStr(1, t, "SOCIETY", vbTextCompare) 0 Then
Cells(i, 2) = "ASSC/FNDN"
ElseIf InStr(1, t, "FOUNDATION", vbTextCompare) 0 Then
Cells(i, 2) = "ASSC/FNDN"
End If
Next i

End Sub


Three things to note:

First, in the IF with INC - I used " INC" so that "SINCE" wouldn't trigger it.

Second, add an ELSE and blank out column 2 if you'd like. As it is if you change a value in column 1 and re-run it, old values may not be replaced correctly.

Third, I used vbTextCompare so that it would not be case sensitive.

Art

"DaveB" wrote:

Can you please help me with some code:

If in columns 1-3000, there is a sentence with "INC" in
it, then in column 2 the word "CORP" should appear.

If in columns 1-3000, there is a sentence with "SOCIETY"
in it, then in column 2 the word "ASSC/FNDN" should appear.

If in columns 1-3000, there is a sentence
with "FOUNDATION" in it, then in column 2 the
word "ASSC/FNDN" should appear.

If in columns 1-3000, there is a sentence
with "UNIVERSITY" in it, then in column 2 the word "ACAD"
should appear.

Thanks. DaveB

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
Help with some simple code Angeline Excel Discussion (Misc queries) 4 October 12th 06 09:06 AM
Simple Code, I think... [email protected] Excel Worksheet Functions 1 August 2nd 06 08:09 PM
simple code gavmer[_5_] Excel Programming 4 May 19th 04 03:32 AM
Some simple code WiReLaD Excel Programming 1 October 30th 03 07:11 PM
Simple For Each Next code Keith Willshaw Excel Programming 0 July 28th 03 12:57 PM


All times are GMT +1. The time now is 05:44 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"