Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9103843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T01:43:35+00:00 2026-06-17T01:43:35+00:00

I am new to VBA programming in excel and would like to know how

  • 0

I am new to VBA programming in excel and would like to know how to do the following (I have searched google and will post what I have tried here with sample code).

Column G, starting at G11 continuing to the end of the sheet, contains 2 values: either “Full Time” or “Part Time”.

In column S, starting at S11 continuing until the end of the sheet, our accountant will enter a Dollar value. The Accountant wants the excel cell in Column G to block/clear out any data and have a popup message saying that “You cannot edit this Cell in Column G as the employee is Part Time”.

I used this code, but it only works for Row 11. I would like this to work for every row in Column G. Do you have any pointers or tips? Thanks in advance.
I use the 2 events Change and SelectionChange

Private Sub Worksheet_Change(ByVal Target As Range)
If [$G11] = "Part Time" Then
[$S11].Interior.ColorIndex = 34
[$S11].ClearContents
[$S11].Locked = True
Else
[$S11].Interior.ColorIndex = 12
[$S11].Locked = False
End If
End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If [$G11] = "Part Time" Then
[$S11].ClearContents
[$S11].Locked = True
Else
[$S11].Locked = False

End If
End Sub 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T01:43:37+00:00Added an answer on June 17, 2026 at 1:43 am

    Try this out. I made some assumptions based on what you wrote, so if it doesn’t quite fit your data, let me know.

    Private Sub Worksheet_Change(ByVal Target As range)
    
    If Not Intersect(Target, .Columns("S:S")) Is Nothing Then 'only do this if column S is changed
    
        Application.EnableEvents = False
    
        If range("G" & Target.Row) = "Part Time" Then
    
            With range("S" & Target.Row)
                .Interior.ColorIndex = 34
                .ClearContents
                .Locked = True
            End With
    
        Else
    
            With range("S" & Target.Row)
                .Interior.ColorIndex = 12
                .Locked = False
            End With
    
        End If
    
        Application.EnableEvents = True
    
    End If
    
    End Sub
    
    Private Sub Worksheet_SelectionChange(ByVal Target As range)
    
    If Not Intersect(Target, .Columns("S:S")) Is Nothing Then 'only do this if column S is changed
    
        Application.EnableEvents = False
    
        If range("G" & Target.Row) = "Part Time" Then
    
            With range("S" & Target.Row)
                .ClearContents
                .Locked = True
            End With
    
        Else
            range("S" & Target.Row).Locked = False
    
        End If
    
        Application.EnableEvents = True
    
    End If
    
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to VBA but have previous experience with PHP programming logic and
I have problem creating new instance of excel 2007 using VBA (from Access 2002).
I'm very new to programming and I'm just starting to learn VBA with excel.
Hi I am very new to VBA Excel Programming. I keep getting a User-defined
I'm very new with VBA Excel and i only know the things as far
I'm very new to VBA and i searched and searched on Google, but can't
I'm fairly new to VBA, however I have a programming background. I'm writing VBA
Hi new to vba in excel 2007 Here is the scenario I want to
I am new to VBA in Excel, and I have a basic userform which
I am new to VBA (I mean, REALLY new) and I would like you

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.