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

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
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,215,067
Messages
6,122,949
Members
449,095
Latest member
nmaske

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