At the most basic, I am trying to find the return value of two subtracted numbers pulled from the assigned value of two different text strings.
Last week, I understood what Functions are, and that Subs do not return a value, and I am still learning how to use functions, and would appreciate your help.
I have rows of varying cells of 102 different categories, and I want to evaluate which categories are used and are given each an unique position number. For example, Child is always in position #3, and Moms are always in position #9. In the spreadsheet, they are in cells AG10 and AH10 respectively. I want to perform a math to do (moms - child) or (9 - 3) to get the return value of 6. I am trying to use this function's return value as a part of a loop in a Call Sub (example: Call tab(returnValue)).
I am not sure which one to use that will work the best: VLOOKUP or Array to assign value to each category. Here are the code I am trying to work with.
Please let me know if you need me to clarify a point or two. The macro I'm developing is complicated, but I am essentially creating a macro to perform hundreds of computer shortcuts (CRTL+V; C; ALT+[Down arrow key], [Space bar], etc. Yes, this does mean I am using SendKeys, but as far as I am aware, the code works beautifully for what I need to do because all I am really doing is taking data from Excel into an intranet web form that will not take it in another way or we'd overwhelm the servers with multiple entries. The html form input type=".." does not work because the type is all shown as "hidden".
Thank you in advance!
Last week, I understood what Functions are, and that Subs do not return a value, and I am still learning how to use functions, and would appreciate your help.
I have rows of varying cells of 102 different categories, and I want to evaluate which categories are used and are given each an unique position number. For example, Child is always in position #3, and Moms are always in position #9. In the spreadsheet, they are in cells AG10 and AH10 respectively. I want to perform a math to do (moms - child) or (9 - 3) to get the return value of 6. I am trying to use this function's return value as a part of a loop in a Call Sub (example: Call tab(returnValue)).
I am not sure which one to use that will work the best: VLOOKUP or Array to assign value to each category. Here are the code I am trying to work with.
Code:
Sub valueX()
Dim last_col As String
last_col = Range("A1").End(xlRight).Row 'Last column
Dim i As Integer
Dim mov As variant
Dim cur As variant
mov = ActiveCell.Offset(0, 1).Select ' goes to next cell
cur = ActiveCell
Call getExcel
mov
For i = 0 To last_col
If IsEmpty(cur) Then
Call beep
Exit Sub
ElseIf c = "Adults" Then
' perform math here somewhere?
Call dosomething
Call tab(n)
Call dosomething
ElseIf c = "Child" Then 'children with disabilities
' perform math here somewhere?
Call dosomething
Call tab(n)
Call dosomething
ElseIf c = "moms" Then
' perform math here somewhere?
Call dosomething
Call tab(n)
Call dosomething
' Do this for all 102 unique categories, unless there's a better way to loop all if--then statements to find out what contains in the cell?
Next
End Sub
Function re(n As Integer) As Integer
Dim c As Integer
Dim previous As Integer
Dim aNext As Integer
Dim catArr As Variant
catArr = vaLook.Range("B1:C105").Value
previous = ActiveCell.Offset(0, -1).Select 'using previous and aNext to subtract two numbers of text string's assigned value
aNext = ActiveCell.Offset(0, 1).Select
' Could I Dim adults = Application.WorksheetFunction.Vlookup("Adults",vaLook,2,0) to get value of 1, and
' then Dim Childs for value of 3, and subtract the two numbers to get value of 2?
' What else can I do in this code to get return value of n?
n = re(previous - aNext)
ReturnValue = n
End Function
'Below is the array I set up in case it works better than VLOOKUP.
Sub lottaArray()
c("Adults with Disabilities") = 1
c("Children with Disabilities") = 2
c("Children / Youth") = 3
c("Dads") = 4
c("Grandfamilies") = 5
c("Grandparents") = 6
c("Low-income Families") = 7
c("Men") = 8
c("Moms") = 9
' .. other categories ..
' VLOOKUP also has it set up like this in two columns as well.
End Sub
Please let me know if you need me to clarify a point or two. The macro I'm developing is complicated, but I am essentially creating a macro to perform hundreds of computer shortcuts (CRTL+V; C; ALT+[Down arrow key], [Space bar], etc. Yes, this does mean I am using SendKeys, but as far as I am aware, the code works beautifully for what I need to do because all I am really doing is taking data from Excel into an intranet web form that will not take it in another way or we'd overwhelm the servers with multiple entries. The html form input type=".." does not work because the type is all shown as "hidden".
Thank you in advance!
Last edited: