MyCell. Value = "total"

S

simplymidori76

A wonderful programmer provided me with this code and I would like for
it to work only if the row "contains" the text "total".

This doesn't work unless the cell specifically says "total".

Thanks for your help in advance.


Option Explicit
Dim MyCell, MyRng As Range
Dim i As Integer


Private Sub CommandButton1_Click()
Set MyRng = [a1:a65000] 'set your range
For Each MyCell In MyRng
If MyCell.Value = "total" Then
MyCell.Offset(1, 0).Select
Do While i < 4
ActiveCell.EntireRow.Insert
i = i + 1
Loop
ActiveCell.Value = "Avails"
ActiveCell.EntireRow.Interior.ColorIndex = 5
ActiveCell.Offset(1, 0).Value = "Left"
ActiveCell.Offset(1, 0).EntireRow.Interior.ColorIndex = 6
End If
Next MyCell
End Sub
 
P

paul.robinson

Hi
Replace the offending bit with
If Instr(MyCell.Value,"total")>0 then

regards
Paul
 
S

simplymidori76

Does this look right. For some reason it doesn't work still...


Option Explicit
Dim MyCell, MyRng As Range
Dim i As Integer


Private Sub CommandButton1_Click()
Set MyRng = [a1:a5000]
For Each MyCell In MyRng
If InStr(MyCell.Value, "total") > 0 Then
MyCell.Offset(1, 0).Select
Do While i < 4
ActiveCell.EntireRow.Insert
i = i + 1
Loop
ActiveCell.Value = "Avails"
ActiveCell.EntireRow.Interior.ColorIndex = 5
ActiveCell.Offset(1, 0).Value = "Left"
ActiveCell.Offset(1, 0).EntireRow.Interior.ColorIndex = 6
End If
Next MyCell
i = 0
End Sub
 
S

simplymidori76

Ahh it works. Had to change the casing. "Total"

Now just 1 more thing... to this code and I will post separate.

Thanks for your help!!!!!

Paul
 

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