IF Statement / Macro --- I tried!

C

CherylH

I need to create an IF statement and need some help! I am building a table
and I need to look at the "status" column in order to insert the appropriate
value in the following column.

Here is what I want my IF statement to do (in English)!:

IF cell E2 = "Not Started", place a "1" in this cell
IF cell E2 = "Active", place a "2" in this cell
IF cell E2 = "Transferred", place a "3" in this cell
IF cell E2 = "Completed", place a "4" in this cell
otherwise, keep <blank>

Now, I need this same thing to occur with all the cells that are populated
in column E - so, I would need the same "IF" statement to apply to "E3, E4,
etc". IS there a way I can copy the actual formula and it will automatically
change to reflect the appropriate column number?

Any help would be appreciated!
 
P

Pranav Vaidya

do you want the formula to change the contents of the cell in which you are
entering the formula? I mean the formula is entered in E2 and you want 1 or 2
or 3 in the same cell?
 
H

Harold Druss

CherylH said:
I need to create an IF statement and need some help! I am building a table
and I need to look at the "status" column in order to insert the
appropriate
value in the following column.

Here is what I want my IF statement to do (in English)!:

IF cell E2 = "Not Started", place a "1" in this cell
IF cell E2 = "Active", place a "2" in this cell
IF cell E2 = "Transferred", place a "3" in this cell
IF cell E2 = "Completed", place a "4" in this cell
otherwise, keep <blank>

Now, I need this same thing to occur with all the cells that are populated
in column E - so, I would need the same "IF" statement to apply to "E3,
E4,
etc". IS there a way I can copy the actual formula and it will
automatically
change to reflect the appropriate column number?

Any help would be appreciated!

Try this:

**************************************************************************
Sub CheckCell()
Dim iRow As Integer, iCol As Integer

iCol = 3

With ActiveDocument.Tables(1)
For iRow = 1 To .Rows.Count
Select Case Left(.Cell(iRow, iCol).Range.Text, Len(.Cell(iRow,
iCol).Range.Text) - 2)
Case "Not Started"
.Cell(iRow, iCol).Range.Text = "1"
Case "Active"
.Cell(iRow, iCol).Range.Text = "2"
Case "Transferred"
.Cell(iRow, iCol).Range.Text = "3"
Case "Completed"
.Cell(iRow, iCol).Range.Text = "4"
Case Else
.Cell(iRow, iCol).Range.Text = ""
End Select
Next
End With

End Sub
****************************************************************************
Good luck
Harold
 
C

CherylH

Hi Pranav, thanks for responding -
I want the resulting value (1,2,3,4) NOT in the same cell as I need to KEEP
these values "as is" --> it will be placed in the cell directly to the right
of it - in the following column (so, if looking at the value in E2, the
1,2,3,4 would be placed in F2, etc).
 
C

CherylH

Hi Harold,
I've never worked with this stuff before. How and where do I place your
code in the Word document? Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top