Consulting

Results 1 to 4 of 4

Thread: VBA FORCE CELL NOT WORKING

  1. #1
    VBAX Regular
    Joined
    May 2012
    Posts
    79
    Location

    VBA FORCE CELL NOT WORKING

    Can anybody see a fault with the following script as it just does not appear to work. The aim is to force users to populate cells before closing unless the workbook was opened as read only:

    Private Sub Workbook_BeforeClose(Cancel As Boolean)

    With Sheets("adhoc and change of status")

    If Not Me.ReadOnly Then

    If WorksheetFunction.CountA(.Range("C4091:C6000,D40916000,F4091:F6000,M4091:M6000,N4091:N6000,P4091:P6000,Q4091:Q6000")) <> 3 Then

    MsgBox "You must complete C, D, F, M, N, P, Q as you did not open the spreadsheet read-only"

    Cancel = True

    End If

    End If

    End With

    End Sub

  2. #2
    VBAX Regular
    Joined
    May 2012
    Posts
    79
    Location
    I have no idea how that little blue face got there, it should read D!

  3. #3
    Please use code tags !!

  4. #4
    VBAX Newbie
    Joined
    Feb 2013
    Posts
    2
    Location

    May help

    This may help a bit

    [VBA]Private Sub Workbook_BeforeClose(Cancel As Boolean)

    Dim a As Range
    Dim b As Range
    Dim wkstfnc As Double
    With Sheets("adhoc and change of status")
    Set a = .Range("A1:A2")
    Set b = .Range("B1:B2")
    End With
    wkstfnc = WorksheetFunction.CountA(a, b)
    If Not ThisWorkbook.ReadOnly Then

    If wkstfnc <> 3 Then

    MsgBox "You must complete C, D, F, M, N, P, Q as you did not open the spreadsheet read-only"

    Cancel = True

    End If

    End If
    Stop
    End Sub
    [/VBA]

Posting Permissions

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