+ Reply to Thread
Results 1 to 4 of 4

Workbook close event

  1. #1
    Registered User
    Join Date
    08-15-2006
    Posts
    10

    Workbook close event

    Hi,

    I need to add validation which sees if any of the cells in a column are empty. If yes, then I need to show a message to the user.

    I need to write this dynamically in VB.net depending on the number of rows.
    How do I do this?

    KPC

  2. #2
    Otto Moehrbach
    Guest

    Re: Workbook close event

    Perhaps something like this: HTH Otto
    Private Sub Workbook_BeforeClose(Cancel As Boolean)
    With Sheets("TheShtName")
    Set Rng = .Range("A1", .Range("A" & Rows.Count).End(xlUp))
    End With
    If Rng.Count > Application.CountA(Rng) Then
    MsgBox "Some empty cells."
    Cancel = True
    End If
    End Sub

    "kpriyac" <kpriyac.2cqp3q_1155911110.193@excelforum-nospam.com> wrote in
    message news:kpriyac.2cqp3q_1155911110.193@excelforum-nospam.com...
    >
    > Hi,
    >
    > I need to add validation which sees if any of the cells in a column are
    > empty. If yes, then I need to show a message to the user.
    >
    > I need to write this dynamically in VB.net depending on the number of
    > rows.
    > How do I do this?
    >
    > KPC
    >
    >
    > --
    > kpriyac
    > ------------------------------------------------------------------------
    > kpriyac's Profile:
    > http://www.excelforum.com/member.php...o&userid=37535
    > View this thread: http://www.excelforum.com/showthread...hreadid=573077
    >




  3. #3
    Registered User
    Join Date
    08-15-2006
    Posts
    10

    Question

    what does the end do in the following statement -

    Set Rng = .Range("A1", .Range("A" & Rows.Count).End(xlUp))

  4. #4
    Dave Peterson
    Guest

    Re: Workbook close event

    It's like hitting the END key on the keyboard.

    The code says to go to .range("a" & rows.count)
    which is the same as
    ..range("a65536") (the bottom cell in column A)

    So if you were doing it manually, you'd go to A65536, hit the End key and
    finally the up arrow key (xlup in code).

    It finds the last use cell in that column (A).


    kpriyac wrote:
    >
    > what does the end do in the following statement -
    >
    > Set Rng = .Range("A1", .Range("A" & Rows.Count).End(xlUp))
    >
    > --
    > kpriyac
    > ------------------------------------------------------------------------
    > kpriyac's Profile: http://www.excelforum.com/member.php...o&userid=37535
    > View this thread: http://www.excelforum.com/showthread...hreadid=573077


    --

    Dave Peterson

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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