Results 1 to 22 of 22

Incorporating 2 codes/Functions together!

Threaded View

HonestlyUgly Incorporating 2... 02-17-2018, 07:21 AM
AlphaFrog Re: Incorporating 2... 02-17-2018, 09:04 AM
HonestlyUgly Re: Incorporating 2... 02-17-2018, 09:18 AM
AlphaFrog Re: Incorporating 2... 02-17-2018, 09:22 AM
HonestlyUgly Re: Incorporating 2... 02-17-2018, 09:26 AM
AlphaFrog Re: Incorporating 2... 02-17-2018, 09:29 AM
HonestlyUgly Re: Incorporating 2... 02-17-2018, 09:33 AM
AlphaFrog Re: Incorporating 2... 02-17-2018, 09:42 AM
HonestlyUgly Re: Incorporating 2... 02-19-2018, 02:17 PM
AlphaFrog Re: Incorporating 2... 02-19-2018, 04:38 PM
HonestlyUgly Re: Incorporating 2... 02-20-2018, 07:43 AM
AlphaFrog Re: Incorporating 2... 02-20-2018, 08:46 AM
HonestlyUgly Re: Incorporating 2... 02-20-2018, 08:54 AM
AlphaFrog Re: Incorporating 2... 02-20-2018, 09:10 AM
HonestlyUgly Re: Incorporating 2... 02-20-2018, 09:24 AM
HonestlyUgly Re: Incorporating 2... 02-25-2018, 07:29 AM
AlphaFrog Re: Incorporating 2... 02-25-2018, 08:58 AM
HonestlyUgly Re: Incorporating 2... 02-25-2018, 10:18 AM
AlphaFrog Re: Incorporating 2... 02-25-2018, 10:56 AM
HonestlyUgly Re: Incorporating 2... 02-27-2018, 02:28 PM
AlphaFrog Re: Incorporating 2... 02-27-2018, 09:43 PM
HonestlyUgly Re: Incorporating 2... 02-28-2018, 02:19 PM
  1. #1
    Registered User
    Join Date
    02-17-2018
    Location
    United Kingdom
    MS-Off Ver
    2013
    Posts
    20

    Post Incorporating 2 codes/Functions together!

    Hi,

    I have a code that brings in specified inputs from a worksheet incrementally (Min, max, increment values specified). I.e min = 1, max = 5 & increm = 2 would result in 3 unique solutions as the output.

    I also have a code that brings in a list of values that have been specified in a column on the same worksheet to an equation. I.e A list of 5 unique inputs would result in 5 unique solutions at the output.

    My aim is to now incorporate both codes into one function so that I can bring in a range of inputs for one part of an equation, whilst also bringing in an incrementally rising input for another part of the same equation. For example, if i had a list of inputs in a column ranging from 1 to 5 (ie 1, 2, 3, 4, 5) and another input with a min value of 1, a max of 5 and increments of 2 (ie values of 1, 3, 5) I should get 15 individual solutions.

    Any advise, tips, pointers or help with combining these codes will be much appreciated!

    Here is the code that brings in inputs incrementally between a specific min & max.

    
    Function valzArrayExp(min As Double, max As Double, inc As Double)
    
        Dim i As Double, num As Double
        Dim TempArr As Variant
        
        num = (max - min) / inc
        ReDim TempArr(num)
        
        i = 0
        Do Until i = num + 1
            TempArr(i) = min + inc * i
            i = i + 1
        Loop
        
        valzArrayExp = TempArr
    
    End Function
    
     Sub array_elements_input_equation_test()
    
            Dim vValz, answers
            Dim vElements As Double
            Dim i As Double, k As Double
        
            Dim A As Double, B As Double, C As Double
        
            With Worksheets(1)
            A = .Range("C13")
            B = .Range("C6")
            C = .Range("C12")
            vValz = valzArrayExp(.Range("F5"), .Range("F4"), .Range("F6"))   ' (min, max, inc)
            End With
        
            vElements = UBound(vValz) + 1
        
            ReDim answers(vElements - 1)
        
            For i = 0 To vElements - 1
                    answers(k) = (vValz(i) * A * B) / C
                    If Err Then
                        Err.Clear
                        answers(k) = 0
                    End If
                    k = k + 1
            Next i
        
            Range("Z4").Resize(UBound(answers) + 1) = Application.Transpose(answers)
    
        End Sub

    Here is the code that inputs a listed set of values from the worksheet column.

     Sub test()
        
            Dim D As Double
        
            lastrow = Cells(Rows.Count, "L").End(xlUp).Row
            inarr = Range(Cells(1, 1), Cells(lastrow, 12))
            For i = 4 To lastrow
                D = inarr(i, 12)
                Cells(i, 26) = 1 + (20 * D) / 5           'example equation
            Next i
        
        End Sub

    Individually they both work as intended.

    I have combined them as follows.

    
    Sub array_elements_and_Changing_input_equation()
    
    
        Dim vValz, answers
        Dim vElements As Double
        Dim i As Double, k As Double
        
        Dim A As Double, D As Double
        
        With Worksheets(1)
            A = .Range("C6")
            vValz = valzArrayExp(.Range("F5"), .Range("F4"), .Range("F6"))
        End With
        
        lastrow = Cells(Rows.Count, "L").End(xlUp).Row
        inarr = Range(Cells(1, 1), Cells(lastrow, 12))
        For i2 = 4 To lastrow
            D = inarr(i2, 12)
        Next i2
        
        vElements = UBound(vValz) + 1
        
        ReDim answers(vElements - 1)
        
        For i = 0 To vElements - 1
                answers(k) = (vValz(i) * A) / D
                If Err Then
                    Err.Clear
                    answers(k) = 0
                End If
                k = k + 1
        Next i
        
        Range("M4").Resize(UBound(answers) + 1) = Application.Transpose(answers)
    
    End Sub

    This script does not produce any error messages, but it does not work as intended.

    Any help will be very much appreciated.
    Last edited by AliGW; 02-17-2018 at 08:27 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Functions in VBA codes for other languages than english
    By Maradona_10 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-28-2014, 10:14 PM
  2. Replies: 1
    Last Post: 12-10-2013, 12:28 AM
  3. Replies: 0
    Last Post: 10-09-2013, 07:59 PM
  4. Incorporating/Using TimeBomb Codes Into Sheets
    By Eric Excels in forum Excel General
    Replies: 6
    Last Post: 10-05-2011, 07:42 PM
  5. where can i find macro codes for various functions such print, save and save as
    By fellayaboy in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-23-2011, 02:06 AM
  6. Replies: 6
    Last Post: 12-21-2010, 01:37 AM
  7. Incorporating Matrix Functions From Excel
    By LHenkel in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-19-2005, 09:06 AM

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