Excel Query with IF, Vlookup and Data Validation

ANAND KUMAR

New Member
Joined
Oct 20, 2016
Messages
41
Dear Experts,

I found myself in a situation of help - I have a file which is attached at following URL

https://drive.google.com/open?id=0Bxtc6jUuxe_pY0hoQXBsaWNhOTg

So If C24 is Yes then E25 needs a value (from drop down – otherwise it needs an error message to detail the spec). Equally if C24 is No or blank then E25 must also be blank (or show error message)

Same is also true for C22 and E22

How can I lock it too? I also need to add a button at the bottom to export to pdf.

Thanks in Advance for any Help.
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Try this in sheet 1 module.

Howard


Code:
Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)

If Intersect(Target, Range("$C$24")) Is Nothing Or Target.Cells.Count > 1 Then Exit Sub

Dim myCheck

Select Case Range("$C$24").Value
 Case Is = "Yes"
    If Range("E25") = "" Then
       MsgBox "CDU SPEC (E25) must have an entry."
       [E25].Activate
     Else
    End If
    
 Case Is = "No"
    If Range("E25") <> "" Then
       
      myCheck = MsgBox("CDU SPEC (E25) must be blank." _
                & vbCr & vbCr & "          Clear Cell E25 now?", vbYesNo)
      
      If myCheck = vbNo Then
          Exit Sub
        Else
          [E25].ClearContents
          [C24].Activate
      End If
       
    End If
   
End Select
End Sub

I overlooked E22 part. I will re-look the code.

H
 
Last edited:
Upvote 0
Try this instead. Delete entire previous code and paste this in its place.

Howard

Code:
Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("C24,C22")) Is Nothing Or Target.Cells.Count > 1 Then Exit Sub

Dim myCheck    

Select Case Range("$C$24").Value
 Case Is = "Yes"
    If Range("E25") = "" Then
       MsgBox "CDU SPEC (E25) must have an entry."
       [E25].Activate
     Else
    End If
    
    Case Is = "No"
    If Range("E25") <> "" Then
       
      myCheck = MsgBox("CDU SPEC (E25) must be blank." _
                & vbCr & vbCr & "          Clear Cell E25 now?", vbYesNo)
      
      If myCheck = vbNo Then
          Exit Sub
        Else
          [E25].ClearContents
          [C24].Activate
      End If
       
    End If
   
End Select

Select Case Range("$C$22").Value
  Case Is = "Yes"
    If Range("E23") = "" Then
       MsgBox "LABEL SPEC (E23) must have an entry."
       [E23].Activate
     Else
    End If
    
  Case Is = "No"
    If Range("E23") <> "" Then
       
      myCheck = MsgBox("LABEL SPEC (E23) must be blank." _
                & vbCr & vbCr & "          Clear Cell E23 now?", vbYesNo)
      
      If myCheck = vbNo Then
          Exit Sub
        Else
          [E23].ClearContents
          [C22].Activate
      End If
       
    End If
   
End Select

End Sub
 
Upvote 0
Ok. And what about Export into PDF. If I create a button and assign this with above code then would it export the Excel in PDF.

Pls. clarify.
 
Upvote 0
Ok. And what about Export into PDF. If I create a button and assign this with above code then would it export the Excel in PDF.

Pls. clarify.

The code I provided will only take care of the C22, C24, E23 and E25 to the extent that I understand your statement here.

So If C24 is Yes then E25 needs a value (from drop down – otherwise it needs an error message to detail the spec). Equally if C24 is No or blank then E25 must also be blank (or show error message)

The code is a Change_Event macro and is never assigned to a button, it is called into action by a change on the sheet. In this case it responds to changes to either C22 or C24.

Sorry to have overlooked the export to pdf, I don't know how to do that, and I don't understand the lock issue.

Howard
 
Upvote 0
With the macro recorder I was able to get this code to save as PDF. I am uncertain if this is anything that will work for you, but this macro can be assigned to a button on the sheet. I'm pretty sure the file path or whatever its called would need to be changed.

Copy to a standard module.

Howard

Code:
Sub PDF_SAVE_AS()
'
' PDF_SAVE_AS Macro
'
'
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
        "C:\Users\ffff\Documents\Copy of Customer Spec Form.pdf", Quality:= _
        xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
        OpenAfterPublish:=True
End Sub
 
Upvote 0
Did you change the file path to yours?

Maybe try using the macro recorder and Save as PDF(*pdf) in the Save as Type window.

That is how I got the code I posted. When you record, it will include your file path,

Howard
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,771
Members
452,353
Latest member
strainu

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