How to use Functions in VBA with my current code

Akw47

Board Regular
Joined
Nov 6, 2020
Messages
90
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
I am new to VBA. Firstly, the function that I have is :

Function SumNums(pWorkRng As Range, Optional xDelim As String = " ") As Double
Dim arr As Variant
Dim xIndex As Long
arr = Split(pWorkRng, xDelim)
For xIndex = LBound(arr) To UBound(arr) Step 1
SumNums = SumNums + VBA.Val(arr(xIndex))
Next
End Function

Using this, from a cell (etc. F9) filled with characters, 1 White & 2 Red, excel can read 3. However, I need to connect with my other function which based on the value calculated on the same cell (F9), it does the number of times of clicks.

Private Sub CommandButton1_Click()
With Me.CommandButton1
.Tag = Val(.Tag) + 1
If .Tag = SumNums.Cells(9, 6).Value Then
rows(9).Interior.ColorIndex = 10
.Tag = 0
End If
End With
End Sub

But the code ^ there don't work. I also want the row that excel reads to be automatically colour index = 10. Instead of me specifying rows(9).
Thankss.
 
I understand that part, but how do you determine which cell/row to look at?
 
Upvote 0

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
I understand that part, but how do you determine which cell/row to look at?
I thought of making it based on the specific number : row, and the specific column : bags (which will be the same throughout)
 
Upvote 0
I thought of making it based on the specific number : row, and the specific column : bags (which will be the same throughout)
so if my specific number is A1, it will register row(1). & the column of the bags would always be B
 
Upvote 0
If you do not want to hard code the row, then there has to be some way of deciding which row it should be.
How are you going to do that?
 
Upvote 0
If you do not want to hard code the row, then there has to be some way of deciding which row it should be.
How are you going to do that?
Yea I thought it would be based on the scanned specific number row. E.G i scan 6954, it should find where the number is in the excel sheet. if it is at row 2, row 2 would be the row to highlight.
 
Upvote 0
But how are you finding the correct row?
 
Upvote 0
But how are you finding the correct row?
when the scanned specific number matches with the specific number saved in the excel file. (my thoughts)

Or would it be better if my active selection will change to the row where the number matches, so the correct row can be found. (after thinking abt your concerns)
 
Upvote 0
If you haven't figured out how to find the correct row, I suggest you do that before worrying about hard coding the row/cell.
 
Upvote 0
If you haven't figured out how to find the correct row, I suggest you do that before worrying about hard coding the row/cell.
Yep. I would figure it out first. Thanks for your help btw. You really helped to guide and show me which direction to look upon. Thanks thanks
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,287
Members
452,631
Latest member
a_potato

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top