+ Reply to Thread
Results 1 to 8 of 8

adapt VBA code to stop and alert if any cells are blank

  1. #1
    Registered User
    Join Date
    05-21-2014
    Location
    Auckland New Zealand
    MS-Off Ver
    2013
    Posts
    35

    adapt VBA code to stop and alert if any cells are blank

    Hi all, thanks for taking a look.
    I have a VBA code that when activated it copies 6 cells from sheet1 to the next available row in sheet2 - A2:F:2.

    I need help with alerting and stopping the routine if any one of the cells in sheet1 are empty so the user has to input into all cells before the routine will execute.

    does it need a check cells for content
    if error highlight empty cell.

    cheers all.

  2. #2
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: adapt VBA code to stop and alert if any cells are blank

    Can you show us the code you have?

  3. #3
    Registered User
    Join Date
    02-22-2014
    Location
    Ireland
    MS-Off Ver
    Excel 2010
    Posts
    15
    Use a do until is empty loop.

    Put an if statement inside to check if cell is empty.

    The use a msgbox and require input from user.

    Write that value to the cell.

    Check our site for code on counters and total counters as you will need them
    James

  4. #4
    Registered User
    Join Date
    05-21-2014
    Location
    Auckland New Zealand
    MS-Off Ver
    2013
    Posts
    35

    Re: adapt VBA code to stop and alert if any cells are blank

    Hi John.

    here is the code and when I get out of the file I'll add the file so you can comment on the format if you wish.

    Private Sub CommandButton1_Click(#
    Dim sh1 As Worksheet, sh2 As Worksheet
    Dim r1 As Range, r2 As Range
    Dim v1 As Variant, v2 As Variant

    Set sh1 = Worksheets#"Sheet1"#
    Set sh2 = Worksheets#"Sheet2"#

    ' specify the cells that will contain information in sheet1
    v1 = Array#"F5", "F8", "F12", "C19", "E19", "G19", "I19", "C21"#
    ' in the same order specify what columns that info would be
    ' placed in in sheet2
    v2 = Array#"A", "B", "C", "D", "E", "F", "G", "Q"#
    ' find the next open row in sheet2 using column A
    rw = sh2#Cells#Rows#Count, "A"##End#xlUp##Offset#1, 0##Row
    ' Now copy and clear the data
    For i = LBound#v1# To UBound#v1#
    Set r1 = sh1#Range#v1#i##
    Set r2 = sh2.Cells#rw, v2#i##
    r1.Copy r2
    ' clears the value after it is transferred
    r1.ClearContents
    Next i
    End Sub
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    05-21-2014
    Location
    Auckland New Zealand
    MS-Off Ver
    2013
    Posts
    35

    Re: adapt VBA code to stop and alert if any cells are blank

    Another question is - as you may see I have used drop down boxes to populate the fields, F5, F8, F12, and also the start and finish times.

    is this an effective way to do this?

  6. #6
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: adapt VBA code to stop and alert if any cells are blank

    Please comply with Forum Rule No. 3.

    3. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the [#] button at the top of the post window (if you are editing an existing post, press Go Advanced to see the [#] button). The result will appear like this in the post window:

  7. #7
    Registered User
    Join Date
    05-21-2014
    Location
    Auckland New Zealand
    MS-Off Ver
    2013
    Posts
    35

    Re: adapt VBA code to stop and alert if any cells are blank

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    05-21-2014
    Location
    Auckland New Zealand
    MS-Off Ver
    2013
    Posts
    35

    Re: adapt VBA code to stop and alert if any cells are blank

    Thanks John for keeping me informed.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. How to adapt this code to copy unique values in cells
    By RayJay01 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-02-2014, 07:18 AM
  2. Stop Code From Running If A Cell is Blank
    By djfatboyfats in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-18-2014, 07:05 AM
  3. [SOLVED] How to adapt a code to include a range of cells instead of the whole sheet
    By nje in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-08-2013, 08:52 AM
  4. [SOLVED] Adapt VBA code to clear the related cells instead of update
    By michelle 1 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-26-2013, 05:50 AM
  5. [SOLVED] STOP BLANK CELLS
    By JFAZ in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 01-17-2006, 12:40 PM

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