+ Reply to Thread
Results 1 to 2 of 2

error writing to cell if a numeric text box is empty

  1. #1
    Registered User
    Join Date
    06-19-2015
    Location
    Cheltenham, England
    MS-Off Ver
    2013
    Posts
    1

    error writing to cell if a numeric text box is empty

    I have 4 text boxes which may or may not have a numeric value entered. It needs to be a minus so I have formatted as CDbl() as it is numeric

    Code works fine if a number is put in every box but fails if one is left empty. I have tried using an If statement

    If Txt1.value = 0 Then
    Range("B5").Value = 0
    Else
    Range("B5").Value = CDbl(Txt1.Value)*-1
    End If

    If Txt2.Value = 0 Then
    Range("C5"").Value = 0
    Else
    Range("C5").Value = CDbl(Txt2.Value)*-1
    End If

    I have also tried Txt1.Value = " " and IsNull(Txt1.Value).

    All to no avail so how can I get the code to work with random empty text boxes (putting a default of 0 in the text box in makes the form look clumsy.)

  2. #2
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: error writing to cell if a numeric text box is empty

    Try
    Please Login or Register  to view this content.
    When you posted
    I have also tried Txt1.Value = " " and IsNull(Txt1.Value).
    it looks as if there is a space between the quotes. You want it to be quotes with a space or anything else in between for it to represent a blank.
    1N73LL1G3NC3 15 7H3 4B1L17Y 70 4D4P7 70 CH4NG3 - 573PH3N H4WK1NG
    You don't have to add Rep if I have helped you out (but it would be nice), but please mark the thread as SOLVED if your issue is resolved.

    Tom

+ 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. Type Mismatch Error for writing text in a cell
    By PleaseHelpMe3 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-28-2016, 06:29 PM
  2. Writing Data to first empty cell in column A
    By edens2021 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-28-2015, 02:42 PM
  3. Extract numeric value from a cell where Text and Numeric combined in a cell
    By Chandrahaas in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 10-07-2014, 10:58 AM
  4. [SOLVED] Error check and if the cell is not numeric or empty loop to the next item
    By JamesGoulding85 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 07-23-2013, 10:47 AM
  5. [SOLVED] While writing files from another workbook, keep empty cells empty!
    By nivoe in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-09-2012, 12:25 PM
  6. [SOLVED] Combining Validation (empty and numeric) Code for ActiveX Text Box
    By VB@N3wb|3 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 04-13-2012, 10:22 PM
  7. [SOLVED] Error writing value to cell
    By Steven M (remove wax and invalid to reply) in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 04-10-2006, 09:30 AM

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