Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6157997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:52:46+00:00 2026-05-23T20:52:46+00:00

I am trying to create a UDF that takes the values from 4 selected

  • 0

I am trying to create a UDF that takes the values from 4 selected cells and performs a function with it. However I don’t know how to write the function to recognize the cell values. The way I have it currently written I need to input a value. Can anyone help me with this relatively simple problem? This is what I have so far.

Function solubility(anion As String, cation As String, carbon1 As String, carbon2 As String)

EDIT

So for example I am trying to select cells A, C, E, and G and they contain values of Tf, Mi, Ch, and Ch. I will then use these cells refer to corresponding values in a range to calculate and display a final value. THe whole code is provided below.

Function solubility(anion As String, cation As String, carbon1 As String, carbon2 As String)

Dim sum As Double
Dim ncavalue As Long, nanvalue As Long, ncb1value As Long, ncb2value As Long
Dim nca As Long, nan As Long, ncab As Long
Dim coeff As Range, groups As Range

'solubility groups range
groups = Worksheets("Solubility").Range("A2:A33")

'group coefficients range
coeff = Worksheets("Solubility").Range("B2:B33")

'number of groups for each group
ncavalue = Range("AE" & cation.Row)
nanvalue = Range("AC" & anion.Row)
ncb1value = Range("AG" & carbon1.Row)
ncb2value = Range("AI" & carbon2.Row)

j = 0

    For j = 0 To UBound(groups)
        If UCase(anion.Value) = UCase(coeff(j).Value) Then
            'coefficient value
            anvalue = coeff(j).Value
        End If
        If UCase(cation.Value) = UCase(coeff(j).Value) Then
            'coefficient value
            cavalue = coeff(j).Value
        End If
        If cation.Value = "[MIm]" Then
            cavalue = Range("B2")
            ncb1value = ncb1value.Value + 1
        End If
        If UCase(carbon1.Value) = UCase(coeff(j).Value) Then
            'coefficient value
            cb1value = coeff(j).Value
        End If
        If UCase(carbon2.Value) = UCase(coeff(j).Value) Then
            'coefficient value
            cb2value = coeff(j).Value
        End If
    Next j
    sum = anvalue * nanvalue + cavalue * ncavalue + cb1value * ncb1value + cb2value * ncb2value
    solubility = sum + Range("B34").Value
End Function
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T20:52:48+00:00Added an answer on May 23, 2026 at 8:52 pm

    Assuming Row 1, call the Function like this:

    =solubility(A1, C1, E1, G1)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a user defined function in Oracle that will return a
I'm trying to write a UDF to translate a string that is either a
I'm trying create this function such that if any key besides any of the
I am trying to create a UDF that does 2 different things depending on
I'm trying to create a UDF in SQL Server 2005 Express as below: CREATE
I am trying create a WCF service that leverages the WPF MediaPlayer on the
Trying to create my first iPhone app that would play back audio. When I
Trying to create a small monitor application that displays current internet usage as percentage
I trying create a class derivated from System.Web.UI.Page and in override Render i set
Trying to create a simple plugin that simply connects to an ftp site, looks

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.