Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 161
Default Instr

I have the following code:

Private Sub CommandButton1_Click()
Dim a2 As String
Dim b2 As String
Dim costitem As String
Dim rng As Range
Dim codeno As String
Dim ctr As Integer
Dim b1 As String
Dim a1 As String
a1 = Editcostitem.Label2.Caption
b1 = Editcostitem.Label6.Caption
a2 = Editcostitem.TextBox1.Value
b2 = Editcostitem.TextBox2.Value
ctr = 0
If a1 = a2 And b1 = b2 Then
MsgBox ("No changes selected for '" & b1 & " " & a1 & "' cost item")
Else
If b1 = b2 Then
For Each rng In Range("costitemrng").Cells
If InStr(rng.Value, a2) < 0 Then
ctr = ctr + 1
End If
Next
If ctr = 0 Then
ActiveCell = a2
Else
MsgBox ("Cost Item '" & a2 & "' already exists")
End If
End If
If a1 = a2 Then

For Each rng In Range("costcoderng").Cells
If InStr(rng.Value, b2) < 0 Then
ctr = ctr + 1
End If
Next
MsgBox (ctr)
If ctr = 0 Then
ActiveCell.Offset(0, -1) = b2
Else
MsgBox ("Cost Code '" & b2 & "' already exists")
End If
End If
If a1 < a2 And b1 < b2 Then
For Each rng In Range("costitemrng").Cells
If InStr(rng.Value, a2) < 0 Then
ctr = ctr + 1
End If
Next
If ctr = 0 Then
ActiveCell = a2
Else
MsgBox ("Cost Item '" & a2 & "' already exists")
End If
For Each rng In Range("costcoderng").Cells
If InStr(rng.Value, b2) < 0 Then
ctr = ctr + 1
End If
Next
If ctr = 0 Then
ActiveCell.Offset(0, -1) = b2
Else
MsgBox ("Cost Code '" & b2 & "' already exists")
End If
End If
End If



Editcostitem.Hide

End Sub

I have this code to not allow values in a range of cells to match. I think
what I wrote it counts any matching characters in the string. What do I need
to do different?
Thanks
 
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
instr() ? mark kubicki Excel Programming 3 November 16th 06 05:07 PM
InStr Harley Excel Programming 3 August 9th 05 08:55 PM
InStr FGM Excel Programming 3 July 14th 05 08:47 PM
InStr and ADO Al Excel Programming 2 June 17th 04 04:22 PM
InStr used in SQL query dchow Excel Programming 3 July 21st 03 09:09 AM


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