+ Reply to Thread
Results 1 to 4 of 4

Help with VBA code requiring mandatory entry

  1. #1
    Registered User
    Join Date
    10-16-2023
    Location
    Los Angeles, CA
    MS-Off Ver
    Office 365
    Posts
    9

    Help with VBA code requiring mandatory entry

    Hello All,

    I don't work with VBA coding terribly much. What I am trying to do is require a note to be entered in the notes column (see attached spreadsheet) when disability is selected as the status. I have the VBA code good all the way to the point of the note, but even though it says Enter comment in H* (H is the beginning of the notes column), when the note is put in it enters it in column E and not H. I have entered the code I am using below. Thank you for any help and your expertise.

    Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Rows.Count > 1 Or Target.Columns.Count > 1 Then
    Exit Sub
    End If

    Dim com As String
    Dim comm1 As String
    'Specify the range below. Set single column range else the code will error out
    Set isect = Application.Intersect(Target, Range("D11:D62"))
    If isect Is Nothing Then

    Else

    If Target.Value = "Disability" Then
    com = "Enter comment in " & Target.Offset(0, 4).Address(RowAbsolute:=False, columnabsolute:=False)

    Do While comm1 = ""
    comm1 = Application.InputBox(prompt:=com, Type:=2)
    On Error GoTo myloop
    If comm1 = False Then
    comm1 = ""
    End If
    myloop:
    On Error GoTo -1
    Loop
    Target.Offset(0, 1).Value = comm1

    Else
    Target.Offset(0, 1).Value = "" 'Remove this line if not desired
    End If

    End If
    End Sub

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)

    End Sub
    Attached Files Attached Files

  2. #2
    Forum Expert leelnich's Avatar
    Join Date
    03-20-2017
    Location
    Delaware, USA
    MS-Off Ver
    Office 2016
    Posts
    2,807

    Re: Help with VBA code requiring mandatory entry

    Hi MRober1302:
    Perhaps change Target.Offset(0, 1).Value = comm1 to Target.Offset(0, 4).Value = comm1
    Clicking the Add Reputation star below helpful posts is a great way to show your appreciation.
    Please mark your threads as SOLVED upon conclusion (Thread Tools above Post # 1). - Lee

  3. #3
    Registered User
    Join Date
    10-16-2023
    Location
    Los Angeles, CA
    MS-Off Ver
    Office 365
    Posts
    9

    Re: Help with VBA code requiring mandatory entry

    Damn you are quick. Thank you so much. This worked.

  4. #4
    Forum Expert leelnich's Avatar
    Join Date
    03-20-2017
    Location
    Delaware, USA
    MS-Off Ver
    Office 2016
    Posts
    2,807

    Re: Help with VBA code requiring mandatory entry

    You're welcome.
    NOTE: Per forum rules, enclosing VBA code in CODE tags makes your posts much easier to read.
    Just select your code text and click the # button on the edit toolbar. - Lee

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Make cell entry in a range mandatory
    By h4a4r6r6 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-20-2019, 01:03 PM
  2. [SOLVED] Mandatory txtbox entry - Can't restrict USER to bypass this field
    By Gilcano in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 11-28-2015, 03:40 PM
  3. conditional mandatory data entry
    By efendiaz in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 09-06-2014, 08:27 AM
  4. Conditional Mandatory Entry - If one, all three
    By DJBittner in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 11-04-2011, 11:55 AM
  5. Replies: 0
    Last Post: 11-15-2010, 10:41 AM
  6. [SOLVED] Making Cell Entry Mandatory
    By Sue T in forum Excel General
    Replies: 4
    Last Post: 08-17-2005, 11:06 AM
  7. [SOLVED] Mandatory entry for a group of cells?
    By JB in forum Excel General
    Replies: 2
    Last Post: 05-04-2005, 12:06 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1