LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Macro 2 insert formula if part of cell contains specific text

Sub Macro2()

Dim myv As String
Dim mys As String

myv = " v "
mys = " - "

Range("E2").Select

Do Until Selection.Offset(0, -2) = ""
With Selection
If .Offset(0, -2).Value Like "*" & myv & "*" Then
.FormulaR1C1 = "=LEFT(RC[-2],FIND("" v "",RC[-2]))"

ElseIf .Offset(0, 2).Value Like "*" & mys & "*" Then
Selection.FormulaR1C1 = "=LEFT(RC[-2],FIND("" -
"",RC[-2]))"
Else
.Formula = ""
End If

.Offset(1, 0).Select
End With
Loop

End Sub



--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Joek" wrote in message
...
Here is the macro:

Sub Macro2()

Dim myv As String
Dim mys As String

myv = " v "
mys = " - "

Range("E2").Select

Do Until Selection.Offset(0, -2) = ""
If Selection.Offset(0, -2).xlContains = myv Then
Selection.FormulaR1C1 = "=LEFT(RC[-2],FIND("" v
"",RC[-2]))"
ElseIf Selection.Offset(0, 2).xlContains = mys Then
Selection.FormulaR1C1 = "=LEFT(RC[-2],FIND("" -
"",RC[-2]))"
Else
Selection.Formula = ""
End If

Selection.Offset(1, 0).Select

Loop

End Sub

"Bob Phillips" wrote:

What range are you checking, normally the code goes down a column, but
you
are updating later in the column.


--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my
addy)

"Joek" wrote in message
...
I am trying to create macro that will insert a formula in a cell
depending
on
part of the contents of another cell.

E.G.
If cell C2 contains the text " v " (lower case v with spaces each side)
then
input a formula in C4

I need a macro because I nned to check a list of entries for three
different
part text entries.

I can do the loop and IF etc its just the 'If the cell contains.......






 
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 2 insert formula if part of cell contains specific text Don Guillett Excel Programming 0 June 27th 08 01:13 PM
insert text to a specific cell matthewwookie Excel Programming 6 September 27th 05 02:34 AM
insert text to a specific cell moondark[_5_] Excel Programming 0 September 23rd 05 11:36 AM
macro to insert row after specific text Luke Excel Discussion (Misc queries) 2 September 19th 05 04:06 PM
Need macro to insert text string while inside cell (formula) BrianB Excel Discussion (Misc queries) 0 May 31st 05 03:18 PM


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