macro this maybe fast and easy question but ...

eric86vabeach

New Member
Joined
Jan 29, 2014
Messages
23
i want to type something in "B1" and then if it is in sheet 1,2,5 it will get delete and then adds the word "changed" the next cell to the right in "Column B"

Private Sub CommandButton2_Click()

For Each cell In Range(Cells(1, "A"), Cells(Cells(Rows.Count, "A").End(xlUp).Row, "A"))

' i want to replace "B1" with what is typed in "B1" also how do i do this in sheet1 , sheet2 and sheet5 only

If cell.Value Like "B1" Then Rows(cell.Row).ClearContents

Next cell

End Sub
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Hi,
have a play with this & see if goes in direction you are looking for. You will need to change sheet name shown in RED where you are entering value in B1.

Rich (BB code):
Private Sub CommandButton2_Click()
    Dim sh As Worksheet
    Dim checkvalue As Variant
    Dim cell As Range
    Dim i As Long

    checkvalue = Sheets("SheetName").Range("B1").Value
    
    If Len(checkvalue) = 0 Then Exit Sub
    Application.ScreenUpdating = False
    For Each sh In Worksheets(Array("Sheet1", "Sheet2", "Sheet5"))
        For Each cell In sh.Range(sh.Cells(1, "A"), sh.Cells(sh.Cells(sh.Rows.Count, "A").End(xlUp).Row, "A"))
            With cell
                If .Value = checkvalue Then
                    .ClearContents
                    .Offset(0, 1).Value = "changed"
                    i = i + 1
                End If
            End With
        Next cell
    Next sh
Application.ScreenUpdating = True
MsgBox i & " Records Updated.", 48, "Records Updated"
End Sub

Dave
 
Last edited:
Upvote 0

Forum statistics

Threads
1,216,565
Messages
6,131,433
Members
449,652
Latest member
ylsteve

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