Odds need period, evens need semicolon

  • Thread starter Thread starter Curious
  • Start date Start date
C

Curious

A long list of names looks like
Tiger
Cat
Dog
Goose

I want to add a period after Tiger, Dog, and add a semicolon after Cat
and Goose.

What is the feasible approach? Loop will not work, right? How about
array? Can you give me a few lines of codes?

Thanks a lot!

H.Z.
 
Where is this long list of names at? What is the rule that determines which
gets a period and which gets a semi-colon?

Rick
 
Maybe...
=a1&if(mod(row(),2)=1,".",";")

In code:

Option Explicit
Sub testme()

Dim myCell As Range
Dim myRng As Range
Dim wks As Worksheet

Set wks = Worksheets("sheet1")

With wks
Set myRng = .Range("A1", .Cells(.Rows.Count, "A").End(xlUp))
End With

For Each myCell In myRng.Cells
If myCell.Row Mod 2 = 0 Then
myCell.Value = myCell.Value & ";"
Else
myCell.Value = myCell.Value & "."
End If
Next myCell
End Sub
 

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

Back
Top