Replace value in another cell based on criteria

Zzz999

New Member
Joined
Jul 1, 2015
Messages
24
Hello. I need to find the cells in column A that has the word Total in it, and if that row has the word Total in it it will replace the value of column C with 1. Here's my sample table:

TeamPurchaserTotal
Foot rugs
25
Amplifier Total0
Sandwich984
Can opener 659
Mouse Total0
Keyboard87
Flask7
Switch7
Hat Total0
Eyeglass676
Shoes 75
Phone Total0
Microphone99
Box3

<tbody>
</tbody>

As you can see, the cells in column C with the word Total in column A are zero. The zeroes must be replaced by 1. I am totally in the dark on how to replace it using the word Total. I'm still grasping the basics of vba and I need to do it using vba only. I've been searching for a code that will fit my need but no luck. Any suggestion will be appreciated. Thank you!
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Code:
[color=darkblue]Sub[/color] Totals()
    
    [color=darkblue]Dim[/color] Found [color=darkblue]As[/color] Range, FirstFound [color=darkblue]As[/color] [color=darkblue]String[/color]
        
    [color=darkblue]Set[/color] Found = Range("A:A").Find(What:="Total", _
                                  LookIn:=xlValues, _
                                  LookAt:=xlPart, _
                                  SearchOrder:=xlByRows, _
                                  SearchDirection:=xlNext, _
                                  MatchCase:=False)
                                  
    Application.ScreenUpdating = [color=darkblue]False[/color]
                
    [color=darkblue]If[/color] [color=darkblue]Not[/color] Found [color=darkblue]Is[/color] [color=darkblue]Nothing[/color] [color=darkblue]Then[/color]
        FirstFound = Found.Address
        [color=darkblue]Do[/color]
            Found.Offset(, 2).Value = 1
            [color=darkblue]Set[/color] Found = Range("A:A").FindNext(After:=Found)
        [color=darkblue]Loop[/color] [color=darkblue]Until[/color] Found.Address = FirstFound
    [color=darkblue]End[/color] [color=darkblue]If[/color]
    
    Application.ScreenUpdating = [color=darkblue]True[/color]
[color=darkblue]End[/color] [color=darkblue]Sub[/color]
 
Upvote 0
Try this:

Code:
Sub Total()
Dim i As Long
Dim lr As Long
lr = Range("A" & Rows.Count).End(xlUp).Row


Application.ScreenUpdating = False
For i = 2 To lr
    If InStr(Range("A" & i), "Total") Then
    Range("C" & i).Value = 1
    End If
Next i


Application.ScreenUpdating = True
MsgBox "complete"
End Sub
 
Upvote 0
Try this:
Code:
Sub Total_Me()
Application.ScreenUpdating = False
Dim i As Integer
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "A").End(xlUp).Row
    For i = 1 To Lastrow
        If InStr(Cells(i, 1).Value, "Total") Then
            Cells(i, 3).Value = "1"
            End If
    Next
Application.ScreenUpdating = True
End Sub
 
Upvote 0
I also tried the last code, still doesn't work. In my excel file, the Amount column is located in column N. I only placed it in column C for illustration purposes. Thank you for making a great effort in helping a beginner like me.
 
Upvote 0
So what column should we look in for the word "Total"?
And what column do you want the "1" put in.

We can only work with the information you give us.
Your quote:
Hello. I need to find the cells in column A that has the word Total in it, and if that row has the word Total in it will replace the value of column C with 1. Here's my sample table:
 
Upvote 0
Try this:
Code:
Sub Total_Me()
Application.ScreenUpdating = False
Dim i As Integer
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "A").End(xlUp).Row
    For i = 1 To Lastrow
        If InStr(Cells(i, 1).Value, "Total") Then
            Cells(i, 3).Value = "1"
            End If
    Next
Application.ScreenUpdating = True
End Sub


Hello. I tried the code. It only replaced the first Total with 1. The rest, still the same (0)
 
Upvote 0
The column with the word Total is column A, and the other column is column N, for "1". I only used column C just to illustrate the table.
 
Upvote 0
Try this:
Code:
Sub Total_Me()
Application.ScreenUpdating = False
Dim i As Integer
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "A").End(xlUp).Row
    For i = 1 To Lastrow
        If InStr(Cells(i, 1).Value, "Total") Then
            Cells(i, 14).Value = "1"
            End If
    Next
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,018
Messages
6,128,305
Members
449,439
Latest member
laurenwydo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top