Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Adding digits in a column based on data in a separate column | Excel Discussion (Misc queries) | |||
Search for a column based on the column header and then past data from it to another column in another workbook | Excel Programming | |||
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 | Excel Programming | |||
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 | Excel Discussion (Misc queries) | |||
how to move the cursor to column A after entering data column F | New Users to Excel |