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

  • Home
  • SEARCH
  • 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 902371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T15:42:21+00:00 2026-05-15T15:42:21+00:00

I keep getting an error 1004 for this line in my VBA Macro Editor:

  • 0

I keep getting an error 1004 for this line in my VBA Macro Editor:

If ActiveCell.Name.Name = "DayShift" Or ActiveCell.Name.Name = "AfterShift" Then

Does anyone know why? This is my whole macro:

Private Sub Worksheet_Change(ByVal Target As Range)

Dim col As Integer
col = ActiveCell.Column
Dim bValue As String
Dim cValue As String

'Check if cell is required to have both columns with value.
    'If it is, skip checks.
    If ActiveCell.Name.Name = "DayShift" Or ActiveCell.Name.Name = "AfterShift" Then

        End

    End If

'Check if active column is column B.
If ColLetter(col) = "B" Then

    'Format value of active cell.
    cValue = "C" + Str(ActiveCell.Row)
    cValue = Replace(cValue, " ", "")

     'Check if cell has value.
     If Range(cValue) = vbNullString Then

     'If it does, remove the opposite shift.
     Else
        MsgBox "This employee has already been assigned for the afternoon shift. In order to allow this change, this employee's scheduling for the afternoon shift will be removed.", vbExclamation
        Range(cValue).ClearContents
     End If

'Check if active column is column C.
ElseIf ColLetter(col) = "C" Then

    'Format value of active cell.
    bValue = "B" + Str(ActiveCell.Row)
    bValue = Replace(bValue, " ", "")

     'Check if cell has value.
     If Range(bValue) = vbNullString Then

     'If it does, remove the opposite shift.
     Else
        MsgBox "This employee has already been assigned for the day shift. In order to allow this change, this employee's scheduling for the day shift will be removed.", vbExclamation
        Range(bValue).ClearContents
     End If

End If
End Sub

Function ColLetter(ColNumber As Integer) As String
    ColLetter = Left(Cells(1, ColNumber).Address(False, False), _
        1 - (ColNumber > 26))
End Function
  • 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-05-15T15:42:22+00:00Added an answer on May 15, 2026 at 3:42 pm

    You have to check for the Name with error handling on. See the code below. I threw in a few other changes too.

    Private Sub Worksheet_Change(ByVal Target As Range)
    
        Dim bValue As String
        Dim cValue As String
        Dim bIsDayShift As Boolean, bIsAfterShift As Boolean
        Dim sMsg As String
    
        Application.EnableEvents = FALSE
    
        sMsg = "This employee has already been assigned for the replaceme shift. "
        sMsg = sMsg & "In order to allow this change, this employee's scheduling "
        sMsg = sMsg & "for the replaceme shift will be removed."
    
        'Check if cell is required to have both columns with value.
        'If it is, skip checks.
        On Error Resume Next
            bIsDayShift = Target.Name.Name = "DayShift"
            bIsAfterShift = Target.Name.Name = "AfterShift"
        On Error GoTo 0
    
        If Not bIsDayShift And Not bIsAfterShift Then
            'Check if active column is column B.
            If Target.Column = 2 Then
                 If Not IsEmpty(Target.Offset(0, 1).Value) Then
                    MsgBox Replace(sMsg, "replaceme", "afternoon"), vbExclamation
                    Target.Offset(0, 1).ClearContents
                 End If
    
            'Check if active column is column C.
            ElseIf Target.Column = 3 Then
                 If Not IsEmpty(Target.Offset(0, -1).Value) Then
                    MsgBox Replace(sMsg, "replaceme", "day"), vbExclamation
                    Target.Offset(0, -1).ClearContents
                 End If
    
            End If
        End If
    
        Application.EnableEvents = TRUE
    
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use slime from CVS (2009-01-05) but keep getting this error: LOAD:
I want to rename a database, but keep getting the error that 'couldn't get
I keep getting a PermGen error on my Tomcat 6 server. I know what
I keep getting tasks that are above my skill level. How can I address this without coming accross as grossly incompetent?
I keep getting this NPE in my application and I can't seem to get
I keep getting error in my iPhone programing when I try to use pi.
For some reason I keep getting error C3861: '__typeof': identifier not found when I
With the following code, I keep getting error C2535 when I compile. It's complaining
I'm trying to do TDD with PyMock, but I keep getting error when I
I am having one heck of a time with hoverIntent. I keep getting Error:

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.