muhammad susanto

Well-known Member
Joined
Jan 8, 2013
Messages
2,077
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
hello all...

i have macro code, but i dont know it works...i have try but still error..

somebody would help me :

this code :
Code:
[COLOR=#333333]Private Sub Worksheet_Change(ByVal Target As Range)[/COLOR]<code style="margin: 0px; padding: 0px; font-style: inherit; font-weight: inherit; line-height: 12px;">    Dim r As Range, rcell As Range
    Set r = Range("A1, B2, C3, D4")
    Application.EnableEvents = False
    For Each rcell In r
        If rcell.Interior.ColorIndex = 14 Then
            rcell = "X"
        Else
            rcell = ""
            
        End If
    Next rcell
    Application.EnableEvents = True
 </code>End Sub

anyone help me is appreciated...

m.susanto
 
Last edited:
Try this and see if it works for you :

Code goes in the ThisWorkbook Module :
Code:
Option Explicit

Private WithEvents oCmndBars As CommandBars


Private Sub Workbook_Open()
    Set oCmndBars = Application.CommandBars
End Sub


Private Sub oCmndBars_OnUpdate()
    RunMacro
End Sub


Private Sub RunMacro()
    Dim r As Range, rcell As Range
    
    Set r = Range("A1, B2, C3, D4")
    Application.EnableEvents = False
    For Each rcell In r
        If rcell.Interior.ColorIndex = 14 Then
            If rcell <> "X" Then
                rcell = "X"
            End If
        Else
            If rcell <> "" Then
                rcell = ""
            End If
        End If
    Next rcell
    Application.EnableEvents = True
 End Sub

The code should get activated after re-opening the workbook or by running the Workbook_Open event routine.
 
Upvote 0

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"

Forum statistics

Threads
1,216,309
Messages
6,130,004
Members
449,552
Latest member
8073662045

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