+ Reply to Thread
Results 1 to 3 of 3

VBA Command Button not working

Hybrid View

  1. #1
    Registered User
    Join Date
    06-14-2017
    Location
    Phoenix, Arizona
    MS-Off Ver
    2013
    Posts
    1

    Question VBA Command Button not working

    I created a command button with a VBA code to print invoices for clients. Yesterday, when I clicked the button it worked, but now when I click the button nothing happens. I have tried all the fixes. I have deleted the button and reset it. I have gone into the VBA design mode and tried running the code from there. Nothing happens.



    I can't figure out why. I have updated, ran the fix from Microsoft, deleted the .exd files, and still nothing. Can someone please help? Here is a copy of the code I wrote.



    Private Sub CommandButton1_Click()
    
    Dim clientname As String
    Dim location As String
    Dim address As String
    Dim r As Long
    Dim slrate As String
    Dim clientrate As String
    Dim discount As String
    Dim payments As String
    Dim balancedue As String
    Dim notes As String
    Dim billingdate As String
    Dim duedate As String
    Dim pastdue As String
    Dim path As String
    Dim myfilename As String
    lastrow = Sheets("June 2017 SL Fees").Range("O" & Rows.Count).End(xlUp).Row
    r = 10
    For r = 10 To lastrow
    If Cells(r, 15).Value = "Detox" Then GoTo nextrow
    If Cells(r, 15).Value = "INPT" Then GoTo nextrow
    If Cells(r, 15).Value = "Discharged" Then GoTo nextrow
    If Cells(r, 15).Value = "" Then GoTo nextrow
    
    
    clientname = Sheets("June 2017 SL Fees").Cells(r, 16).Value
    location = Sheets("June 2017 SL Fees").Cells(r, 15).Value
    address = Sheets("June 2017 SL Fees").Cells(r, 23).Value
    slrate = Sheets("June 2017 SL Fees").Cells(r, 24).Value
    clientrate = Sheets("June 2017 SL Fees").Cells(r, 25).Value
    discount = Sheets("June 2017 SL Fees").Cells(r, 26).Value
    payments = Sheets("June 2017 SL Fees").Cells(r, 28).Value
    balancedue = Sheets("June 2017 SL Fees").Cells(r, 29).Value
    notes = Sheets("June 2017 SL Fees").Cells(r, 30).Value
    billingdate = Sheets("June 2017 SL Fees").Cells(r, 32).Value
    duedate = Sheets("June 2017 SL Fees").Cells(r, 31).Value
    pastdue = Sheets("June 2017 SL Fees").Cells(r, 27).Value
    
    Cells(r, 15).Value = "Detox"
    Cells(r, 15).Value = "INPT"
    Cells(r, 15).Value = "Discharged"
    Cells(r, 15).Value = ""
    Workbooks.Open ("C:\Users\SobaUser\Documents\SL Invoice\SimpleInvoice.xlsx")
    ActiveWorkbook.Sheets("Simple Invoice").Activate
    ActiveWorkbook.Sheets("Simple Invoice").Range("B11").Value = billingdate
    ActiveWorkbook.Sheets("Simple Invoice").Range("A16").Value = clientname
    ActiveWorkbook.Sheets("Simple Invoice").Range("A17").Value = address
    ActiveWorkbook.Sheets("Simple Invoice").Range("B23").Value = slrate
    ActiveWorkbook.Sheets("Simple Invoice").Range("B24").Value = location
    ActiveWorkbook.Sheets("Simple Invoice").Range("B25").Value = discount
    ActiveWorkbook.Sheets("Simple Invoice").Range("B26").Value = clientrate
    ActiveWorkbook.Sheets("Simple Invoice").Range("B27").Value = pastdue
    ActiveWorkbook.Sheets("Simple Invoice").Range("B28").Value = payments
    ActiveWorkbook.Sheets("Simple Invoice").Range("B29").Value = balancedue
    ActiveWorkbook.Sheets("Simple Invoice").Range("B33").Value = duedate
    ActiveWorkbook.Sheets("Simple Invoice").Range("A47").Value = notes
    
    path = "C:\Users\SobaUser\Documents\SL Invoice"
    ActiveWorkbook.SaveAs Filename:=path & clientname & "-" & billingdate & "-" & ".pdf"
    myfilename = ActiveWorkbook.FullName
    Application.DisplayAlerts = True
    'ActiveWorkbook.Printout copies:=1
    ActiveWorkbook.Close SaveChanges:=False
    
    nextrow:
    
    Next r
    
    End Sub
    Moderator's note: Please take the time to review our rules. There aren't many, and they are all important. Rule #3 requires code tags. I have added them for you this time because you are a new member. --6StringJazzer
    Last edited by 6StringJazzer; 06-14-2017 at 02:45 PM.

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: VBA Command Button not working

    Attach a sample workbook. Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.

    You need to step through the macro to see where it fails.

    Instead of clicking on the button, move the macro to a normal macro module.

    Then select the developer tab and then macros.

    Select "Step into Macro" and then f8 to stem through your macro.
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  3. #3
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,757

    Re: VBA Command Button not working

    The behavior could be explained if there are fewer than 10 rows in "June 2017 SL Fees". If you run the code directly from the VBA editor and it still doesn't do anything, the problem is not with your button. Also see if the code is even trying to run--as a quick diagnostic I suggest putting this line just before the For statement:

    MsgBox "lastrow=" & lastrow
    If the message box doesn't appear then your code is not even running. But if it does appear, the problem will likely be evident in the message.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

+ 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. [SOLVED] Active X Command Button not working
    By gassiusmax in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 01-04-2015, 01:29 PM
  2. Command Button Stops Working After First Use
    By OpieWinston in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-03-2014, 06:55 PM
  3. Command Button Not working in new file
    By Fletch74 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 12-05-2013, 11:41 PM
  4. Command button code not working
    By mariposa in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-06-2011, 05:03 AM
  5. Command button is not working by using VBA
    By Webtekr in forum Outlook Programming / VBA / Macros
    Replies: 1
    Last Post: 03-28-2009, 02:22 AM
  6. Command button not working properly on different sheet
    By Strikez in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-07-2007, 12:36 AM
  7. command button isn't working
    By Nydia in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 04-29-2005, 06:06 PM

Tags for this Thread

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