Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Entering Data into Column C based on word from Column A

I am currently trying to figure out a macro that will enter data into
column C depending on a word in Column A

Column A Column B Column C

Dog Doggy
Cat
Elephant
Giraffe
Dog Food Doggy
Cat Food
Elephant Food
Giraffe Food

How do I go about doing this? Any help would be greatly appreciated.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 812
Default Entering Data into Column C based on word from Column A

Dim c As Range
For Each c In Sheet1.Range("A2:A9")
If InStr(LCase(c), "dog") 0 Then c.Offset(0, 2) = "Doggy"
Next c

Hth,
Merjet


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Entering Data into Column C based on word from Column A

after changing the range to encompass the larger range, I receive an
error highlighting

"If InStr(LCase(c), "dog") 0 Then"

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Entering Data into Column C based on word from Column A

Here is another version:
Sub AnmlCrkrs()
Animal = Array("Dog", "Cat", "Elephant", "Giraffe")
lstRw = Cells(Rows.Count, 1).End(xlUp).Row
counter = 0
Do Until counter = 4
For Each c In Range("A2:A" & lstRw)
If c.Value Like "*" & Animal(counter) & "*" Then
cRng = c.Address
If counter = 0 Then
Range(cRng).Offset(0, 2) = "Doggy"
ElseIf counter = 1 Then
Range(cRng).Offset(0, 2) = "Kitty"
ElseIf counter = 2 Then
Range(cRng).Offset(0, 2) = "Pachy"
ElseIf counter = 3 Then
Range(cRng).Offset(0, 2) = "LongNeck"
End If
End If
Next
counter = counter + 1
Loop
End Sub



"J.J." wrote:

I am currently trying to figure out a macro that will enter data into
column C depending on a word in Column A

Column A Column B Column C

Dog Doggy
Cat
Elephant
Giraffe
Dog Food Doggy
Cat Food
Elephant Food
Giraffe Food

How do I go about doing this? Any help would be greatly appreciated.


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 812
Default Entering Data into Column C based on word from Column A

I receive an error highlighting
"If InStr(LCase(c), "dog") 0 Then"


So what was in the cell that caused the error? The code handled blanks
and numbers for me just fine.

Hth,
Merjet




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 396
Default Entering Data into Column C based on word from Column A

Hi JJ, try the following....

Sub Tester()
'
Dim rng As Range, rCell As Range
Dim WB As Workbook, SH As Worksheet
Dim r As Range, lastRow As Long

Set r = ActiveSheet.UsedRange
lastRow = r.Rows.Count
Const sStr As String = "cat" '<<===== CHANGE

Set WB = ActiveWorkbook '<<===== CHANGE
Set SH = WB.Sheets("Sheet1") '<<===== CHANGE
Set rng = SH.Range("A1:A" & lastRow) '<<===== CHANGE Column to
search

For Each rCell In rng.Cells
With rCell
If LCase(rCell.Value) Like "*cat*" Then
rCell.Offset(0, 2).Value = "Cat" '<<=Change
End If
End With
Next rCell
End Sub


Les Stout

*** Sent via Developersdex http://www.developersdex.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
Adding digits in a column based on data in a separate column adriver Excel Discussion (Misc queries) 4 April 21st 10 12:41 AM
Search for a column based on the column header and then past data from it to another column in another workbook minkokiss Excel Programming 2 April 5th 07 01:12 AM
Based on a condition in one column, search for a year in another column, and display data from another column in the same row look [email protected] Excel Programming 2 December 30th 06 06:23 PM
Based on a condition in one column, search for a year in another column, and display data from another column in the same row look [email protected] Excel Discussion (Misc queries) 1 December 27th 06 05:47 PM
how to move the cursor to column A after entering data column F tskaiser New Users to Excel 2 April 29th 06 02:28 PM


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