English 中文(简体)
• 如何组建2010年Excel所需的特别小组
原标题:How to Make a particular Cell Required in Excel 2010
  • 时间:2011-11-24 10:04:22
  •  标签:
  • excel
  • vba
问题回答

Part 1

该法典有几个问题。

  1. You need a Workbook event - there is no WorkSheet_BeforeSave event
  2. You cant test for two blank cells with Sheet1.Range("A3:B3").Value = ""
  3. If the code is running then events are already enabled, so this line Application.EnableEvents = True is redundant

Something like this test for both A3 and B3 being non blank on the leftmost sheet

{编码载于<代码>本工作手册模块}

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
  If Application.WorksheetFunction.CountA(Sheets(1).Range("a3:b3")) <> 2 Then
        MsgBox "Cannot print until required cells have been completed!"
        Cancel = True
    End If
End Sub

虽然你可以使用第2部分的“Reex”数据,但应当进行细致的验证。

a) You can use an "allow" Date in Data Validation

b) 您可在100 000 000至999 999 999 999人之间使用一个总数,即9位数。

Answer to Part 2 (Regular Expression thing)

You can write a user-defined function in VBA and use it in Excel. Here s an example that extracts parts of a string using RegEx, but with a bit of tweaking you can use it to do validation.





相关问题
import of excel in SQL imports NULL lines

I have a stored procedure that imports differently formatted workbooks into a database table, does work on them then drops the table. Here is the populating query. SELECT IDENTITY(INT,1,1) AS ID ...

Connecting to Oracle 10g with ODBC from Excel VBA

The following code works. the connection opens fine but recordset.recordCount always returns -1 when there is data in the table. ANd If I try to call any methods/properties on recordset it crashes ...

Excel date to Unix timestamp

Does anyone know how to convert an Excel date to a correct Unix timestamp?

C# GemBox Excel Import Error

I am trying to import an excel file into a data table using GemBox and I keep getting this error: Invalid data value when extracting to DataTable at SourceRowIndex: 1, and SourceColumnIndex: 1. As ...

Importing from excel "applications" using SSIS

I am looking for any tips or resources on importing from excel into a SQL database, but specifically when the information is NOT in column and row format. I am currently doing some pre-development ...

热门标签