Results 1 to 11 of 11

InputBox data not adding

Threaded View

  1. #1
    Registered User
    Join Date
    01-09-2019
    Location
    Toronto Canada
    MS-Off Ver
    Office 10
    Posts
    30

    InputBox data not adding

    1. a) Macro button (located at cell M6 “Click to TOTAL cost of Stock Purchase Amounts”, that adds up various numbers, selected by the user. Firstly, the User will select the cell where the total is to go, and then click on each amount to be added. There is provision for 8 numbers to be added, however, the total only appears if all eight are utilized. If less than 8 are selected (user would click the cancel button to stop entering), but the total would not appear.
    b) Secondly, I am unable to use Range Name (TargetSheet) which references a cell holding the sheet name (changes constantly). I am not sure what the error means (COMPILE ERROR – VARIABLE NOT DEFINED) and how to correct it.
    Line causing the error - Sheet(TargetSheet).Activate

    Sub TotalPurchaseAmounts()
    
    Application.Run "UnProtect"
    
    Dim PurchTotalLoc As Variant
    Dim userResponce As Range
    Dim rng1 As Range
    Dim rng2 As Range
    Dim rng3 As Range
    Dim rng4 As Range
    Dim rng5 As Range
    Dim rng6 As Range
    Dim rng7 As Range
    Dim rng8 As Range
    Dim TargetSheet As Range
    
    On Error Resume Next
    
    Application.DisplayAlerts = False
    
    ' Would like to use Range Name "TargetSheet"...but does not work.......COMPILE ERROR - SUB OR FUNCTION NOT DEFINED
    
    ' Sheet(TargetSheet).Activate '*****THIS LINE CAUSES THE ERROR
    
    Sheet1.Activate 'don't want to keep this line as it is static
    
    Application.Run "UnProtect"
    Set userResponce = Application.InputBox("Please select the cell where you want the Total to appear", _
    Title:="Select the cell for your Total", Type:=8)
    If userResponce Is Nothing Then Exit Sub
    
    Let PurchTotalLoc = userResponce.Address
    
    On Error Resume Next
    
    'Ask the user for up to eight cells
    
    Set rng1 = Application.InputBox("Click on first cell to be totalled", "First Cell", , , , , , 8)
    If rng1 = "" Then GoTo ext:
    
    Set rng2 = Application.InputBox("Click on second cell to be totalled", "Second Cell", , , , , , 8)
    If rng2 = "" Then GoTo ext:
    
    Set rng3 = Application.InputBox("Click on third cell to be totalled", "Third Cell", , , , , , 8)
    If rng3 = "" Then GoTo ext:
    
    Set rng4 = Application.InputBox("Click on fourth cell to be totalled", "Fourth Cell", , , , , , 8)
    If rng4 = "" Then GoTo ext:
    
    Set rng5 = Application.InputBox("Click on fifth cell to be totalled", "Fifth Cell", , , , , , 8)
    If rng5 = "" Then GoTo ext:
    
    Set rng6 = Application.InputBox("Click on sixth cell to be totalled", "Sixth Cell", , , , , , 8)
    If rng6 = "" Then GoTo ext:
    
    Set rng7 = Application.InputBox("Click on seventh cell to be totalled", "Seventh Cell", , , , , , 8)
    If rng7 = "" Then GoTo ext:
    
    Set rng8 = Application.InputBox("Click on eigth cell to be totalled", "Eighth Cell", , , , , , 8)
    If rng8 = "" Then GoTo ext:
    
    'Output to a specific user-selected cell (called "PurchTotalLoc") via InputBox
    
    ext:
    Range(PurchTotalLoc) = Application.WorksheetFunction.Sum(rng1, rng2, rng3, rng4, rng5, rng6, rng7, rng8)
    
    'puts total in if one selects 8 amounts, but not if one enters less than 8 and hits "cancel"
    
    Application.Run "Protect"
    
    End Sub
    Attached Files Attached Files
    Last edited by Pepe Le Mokko; 04-16-2020 at 02:13 AM. Reason: Code tags added

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] MACRO: If user clicks cancel in inputbox,then do nothing. Problem with inputbox appearance
    By Tona in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 11-05-2015, 04:33 AM
  2. VBA Code for Adding two cells through Inputbox
    By onlyprasad4u in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-16-2014, 03:16 AM
  3. Finding all Text and adding a inputbox to all search
    By Excelnoub in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-20-2014, 02:21 PM
  4. [SOLVED] Help adding inputbox values
    By Ellen 2Excel in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-09-2014, 04:03 PM
  5. [SOLVED] Trouble adding carrage return/line feed to application.inputbox message
    By welchs101 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-19-2012, 10:14 AM
  6. [SOLVED] Adding a field limitation (0-1 only) to a Private sub inputbox prompt.
    By Coachwooten in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-05-2012, 12:10 PM
  7. Inputbox button control + msgbox for empty inputbox
    By D_Rennie in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-30-2009, 12:39 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