Results 1 to 3 of 3

Textbox Empty to Return 0 as value to the cell

Threaded View

  1. #1
    Registered User
    Join Date
    04-30-2014
    Location
    england
    MS-Off Ver
    Microsoft Excel 365
    Posts
    67

    Textbox Empty to Return 0 as value to the cell

    Greetings to all excel gurus,

    May I know what is the possible way to achieve for what I want the UserForm to be?

    I have 26 text box to be fill and all these text box can leave for empty if there is no sales to enter.

    However I notice is empty text box it would cause my autosum not working correct therefore is it anyway I can replace the empty textbox value to 0 by default?

    Here is my VBA code:

    Private Sub btnSubmit_Click()
    
    Dim Datalog As Worksheet
    
    Set Datalog = ThisWorkbook.Sheets("Datalog")
    
    'New Row 1
    nr = Datalog.Cells(Rows.Count, 5).End(xlUp).Row + 1
    
    Datalog.Cells(nr, 2) = Me.tbDate1
    Datalog.Cells(nr, 3) = Me.tbSample1
    Datalog.Cells(nr, 5) = Me.tbItem1
    
    Datalog.Cells(nr, 8) = Me.tbSample2
    Datalog.Cells(nr, 10) = Me.tbItem2
    
    Datalog.Cells(nr, 13) = Me.tbSample3
    Datalog.Cells(nr, 15) = Me.tbItem3
    
    Datalog.Cells(nr, 18) = Me.tbSample4
    Datalog.Cells(nr, 20) = Me.tbItem4
    
    Datalog.Cells(nr, 23) = Me.tbSample5
    Datalog.Cells(nr, 25) = Me.tbItem5
    
    Datalog.Cells(nr, 28) = Me.tbSample6
    Datalog.Cells(nr, 30) = Me.tbItem6
    
    Datalog.Cells(nr, 33) = Me.tbSample7
    Datalog.Cells(nr, 35) = Me.tbItem7
    
    Datalog.Cells(nr, 38) = Me.tbSample8
    Datalog.Cells(nr, 40) = Me.tbItem8
    
    Datalog.Cells(nr, 43) = Me.tbSample9
    Datalog.Cells(nr, 45) = Me.tbItem9
    
    Datalog.Cells(nr, 48) = Me.tbSample10
    Datalog.Cells(nr, 50) = Me.tbItem10
    
    Datalog.Cells(nr, 53) = Me.tbSample11
    Datalog.Cells(nr, 55) = Me.tbItem11
    
    Datalog.Cells(nr, 58) = Me.tbSample12
    Datalog.Cells(nr, 60) = Me.tbItem12
    
    'New Row 2
    nr2 = Datalog.Cells(Rows.Count, 5).End(xlUp).Row + 1
    
    Datalog.Cells(nr2, 2) = Me.tbDate2
    Datalog.Cells(nr2, 3) = Me.tbSample13
    Datalog.Cells(nr2, 5) = Me.tbItem13
    
    Datalog.Cells(nr2, 8) = Me.tbSample14
    Datalog.Cells(nr2, 10) = Me.tbItem14
    
    Datalog.Cells(nr2, 13) = Me.tbSample15
    Datalog.Cells(nr2, 15) = Me.tbItem15
    
    Datalog.Cells(nr2, 18) = Me.tbSample16
    Datalog.Cells(nr2, 20) = Me.tbItem16
    
    Datalog.Cells(nr2, 23) = Me.tbSample17
    Datalog.Cells(nr2, 25) = Me.tbItem17
    
    Datalog.Cells(nr2, 28) = Me.tbSample18
    Datalog.Cells(nr2, 30) = Me.tbItem18
    
    Datalog.Cells(nr2, 33) = Me.tbSample19
    Datalog.Cells(nr2, 35) = Me.tbItem19
    
    Datalog.Cells(nr2, 38) = Me.tbSample20
    Datalog.Cells(nr2, 40) = Me.tbItem20
    
    Datalog.Cells(nr2, 43) = Me.tbSample21
    Datalog.Cells(nr2, 45) = Me.tbItem21
    
    Datalog.Cells(nr2, 48) = Me.tbSample22
    Datalog.Cells(nr2, 50) = Me.tbItem22
    
    Datalog.Cells(nr2, 53) = Me.tbSample23
    Datalog.Cells(nr2, 55) = Me.tbItem23
    
    Datalog.Cells(nr2, 58) = Me.tbSample24
    Datalog.Cells(nr2, 60) = Me.tbItem24
    
    'Unload Form
    Unload UserForm1
    
    End Sub
    
    Private Sub btnGoTo_Click()
    
    'Go to Summary Worksheet and Unload Form
    Worksheets(ActiveSheet.Index - 2).Select
    Unload UserForm1
    
    End Sub
    
    Private Sub UserForm_Initialize()
    
    Me.tbDate1 = Format(DateAdd("D", -Weekday(Date), Date), "dd-mmm-yy")
    Me.tbDate2 = Format(DateAdd("D", -Weekday(Date) + 1, Date), "dd-mmm-yy")
    
    End Sub
    Thank you.
    Last edited by lazyserv; 05-27-2015 at 04:25 AM. Reason: solved

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Place Textbox Value to the next empty cell
    By weeeee0713 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-25-2014, 04:20 AM
  2. [SOLVED] Transfer textbox value to next empty cell under same row
    By smartbuyer in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-24-2014, 01:01 AM
  3. [SOLVED] Checking for empty textbox and setfocus the empty textbox
    By subbby in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-23-2013, 02:49 PM
  4. [SOLVED] Textbox.caption to cell if empty, how?
    By WTG in forum Excel General
    Replies: 2
    Last Post: 02-27-2005, 01:06 AM
  5. [SOLVED] Textbox.caption to cell if empty, how?
    By WTG in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-27-2005, 01:06 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