Adding Area Code To Phone Numbers

M

Minitman

Greeting,

I am adding the area codes to a list of phone numbers. I have some
code that does that. The problem is this list has a mix numbers.
Some with area codes and some with out. I need a way to bypass those
numbers with area codes and add the area codes to these without them.
Some of the numbers also have an extension tacked on, so LEN won't
work.

Here is the code that I have:

Private Sub CommandButton1_Click()
Dim lastrow As Long
Dim row_index As Long
Dim col_index As Integer
Dim text_value
text_value = "(512) "
For col_index = 10 To 14
lastrow = ActiveSheet.Cells(Rows.Count, _
col_index).End(xlUp).Row
For row_index = 1 To lastrow
If Cells(row_index, col_index).Value <> "" Then
Cells(row_index, col_index).Value = text_value & _
Cells(row_index, col_index).Value
End If
Next
Next
End Sub

Anyone have any suggestions on how to exclude these cells which have
an area code already?

Any help would be appreciated.

TIA

-Minitman
 
F

Frank Kabel

Hi
replace the line
If Cells(row_index, col_index).Value <> "" Then

with the line
If Cells(row_index, col_index).Value <> "" and _
InStr(Cells(row_index, col_index).Value,")")=0 then
 

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