How to combine Row Letter with Integer to determine cell value

Zerb

New Member
Joined
Dec 29, 2021
Messages
30
Office Version
  1. 365
Platform
  1. Windows
I have a sheet that has two columns in it, A and B. A has part numbers and B has quantities. I have populated my part numbers into a ComboBox on a UserForm and, at least this is what I think is the best way to do it, I want to use the .ListIndex of that ComboBox to then get the value from the column B in the worksheet so that I can populate another ComboBox. So as an example if the .ListIndex is 4, then I want to get the value of B4 into my VBA as an Integer so I can use that value to populate my second ComboBox. Which will end up being 1-FoundIntegerValue.

VBA Code:
Private Sub PartNumberBox_Change()
Dim Max As Integer


If PartNumberBox.ListIndex <> -1 Then
    QuantityBox.Visible = True
    JobNumberBox.Visible = True
Else
    QuantityBox.Visible = False
    JobNumberBox.Visible = False
End If

Max = Worksheets("OnHand").Cell("B" & PartNumberBox.ListIndex).Offset(1)



End Sub
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Hi.
Have you tried?

VBA Code:
Max = Worksheets("OnHand").Cells(PartNumberBox.ListIndex, "B")
or
VBA Code:
Max = Worksheets("OnHand").Range("B" & PartNumberBox.ListIndex)
 
Upvote 0
I think I have tried the latter but I'd have to go back and look, thanks for the idea! I got it taken care of thought doing it this way as shown below.

The other issue I seemed to run into was that since the .ListIndex starts at 0 for its first value, that actually needed to be offset in my case since my Part Numbers and Quantities don't start until Row 2 on the sheet. Once I setup some Debug.Prints I caught it and sorted it out.

VBA Code:
Private Sub PartNumberBox_Change()
Dim Max As Integer
Dim Row As Integer
Dim Col As Integer
Dim Range As Variant

Let Col = 3


If PartNumberBox.ListIndex <> -1 Then
    QuantityBox.Visible = True
    JobNumberBox.Visible = True
Else
    QuantityBox.Visible = False
    JobNumberBox.Visible = False
End If

If PartNumberBox.ListIndex <> -1 Then
    Row = PartNumberBox.ListIndex + 2
    Set Range = Cells(Row, Col)
    Max = Range.Value
End If
 
Upvote 0
Solution

Forum statistics

Threads
1,214,641
Messages
6,120,692
Members
448,979
Latest member
DET4492

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