Mandatory field to be validated

dalonglong

New Member
Joined
Jul 16, 2020
Messages
13
Office Version
  1. 2016
Platform
  1. Windows
I would like to make a vba to check all the cell below which contains the word 'mandatory' on row 6 are properly filled up.
Those that i have square in red are the potential error that this code should be giving an error message specifying which cell/cells is giving an issue (upon clicking on save button).
i am new to vba and i would like to explore how i can do that using macro. appreciate if anyone can provide some tips to go about doing this.
 

Attachments

  • mandatory field.png
    mandatory field.png
    26.2 KB · Views: 18

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
1. rename current result sheet "Validated Result"
2. amend Validation_Click as below
3. Run the code to prove that works
4. I will post code to link to correct cell in next post

OLD
Rich (BB code):
'insert results sheet
    Application.ScreenUpdating = False
   Set rpt = Sheets.Add
    rpt.Cells(2, 1) = "Cells"
    rpt.Cells(2, 2) = "Remarks"

NEW
Rich (BB code):
'CLEAR results sheet
    Application.ScreenUpdating = False
    Set rpt = Sheets("Validated Result")
    rpt.Cells.Clear
    rpt.Cells(1, 1) = ws.Name
    rpt.Cells(2, 1) = "Cells"
    rpt.Cells(2, 2) = "Remarks"

@Yongle
I would like to go with your input. Hmm. what i mean is after the first sheet is inserted (from the OLD code), then the sub sequence Run will just refresh that Inserted Sheet. That sheet will be call "validated result".
 
Upvote 0
@Yongle

I want it to be updated in the same sheet when i run the code. (the old validated data should be cleared)
 
Upvote 0
Post16# amendments achieve that
What is the problem?
 
Upvote 0
@Yongle

Yes it acheived that by following step 1:
1. rename current result sheet "Validated Result"

However can step 1 be automated
 
Upvote 0
Once the sheet has been renamed manually it will NEVER require renaming again
Why is it required in the VBA ?
What am I missing?
 
Upvote 0
@Yongle

Because it is a repetitive task to rename manually as there are not just 1 same file that require validating. it is a file that is used one time only and not be saved. Therefore it will always require a rename by using this method whenever a new file is needed to check
 
Upvote 0
In that case, try this

Rich (BB code):
1. Insert this where variables are declared
Const Res = "Validated Result"

Rich (BB code):
2. Below this line ...
    Set ws = ActiveSheet
... insert these lines
    If ws.Name = Res Then
        MsgBox "cannot run from results sheet"
        Exit Sub
    End If

Rich (BB code):
3. use this instead of code in post#16
'CLEAR results sheet
    Application.ScreenUpdating = False
    On Error Resume Next
    Set rpt = Sheets(Res)
    On Error GoTo 0
    If rpt Is Nothing Then Set rpt = Sheets.Add
    rpt.Name = Res
    rpt.Cells.Clear
    rpt.Cells(1, 1) = ws.Name
    rpt.Cells(2, 1) = "Cells"
    rpt.Cells(2, 2) = "Remarks"
 
Upvote 0
Thanks, that is exactly what i need,
by having this code, back to the original topic (to link to the cell).. is the below function Application.Goto mentioned in #20 (must be placed in that SHEET's code window) will also need to change accordingly? To placed it in the Sub Validation_Click() instead, i tried shifting it but it could'nt work. appreciate your help!

VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

    On Error Resume Next
    If Target.CountLarge > 1 Then Exit Sub
    Dim cel As Range
    Set cel = Sheets(Range("A1").Value).Range(Target.Value)
    Application.Goto Reference:=cel, scroll:=True
    On Error GoTo 0

End Sub
 
Upvote 0

Forum statistics

Threads
1,217,349
Messages
6,136,051
Members
449,985
Latest member
rittersportyummy

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