Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How can I user a countif formula in a Userform?

Posted on 2012-03-21
4
Medium Priority
?
514 Views
Last Modified: 2012-03-21
The following formula works in an excel worksheet with on problems. I would like to use something similiar if possible. Can anyone help me?

Private Sub TxtBx2_Change()
    If TxtBx2 = "MD" Then
        Me.TxtBx1.Value = Concatenate(Me.TxtBx2.Text, Right(Concatenate("000", CountIf(ReportList![A3:A200], "=" & TxtBx2.Value) + 1, 3)))
    Else
    If TxtBx2 = "SFC" Then
        Me.TxtBx1.Value = Concatenate(Me.TxtBx2.Text, Right(Concatenate("000", CountIf(ReportList![A3:A200], "=" & TxtBx2.Value) + 1, 3)))
    Else
    If TxtBx2 = "DOM" Then
        Me.TxtBx1.Value = Concatenate(Me.TxtBx2.Text, Right(Concatenate("000", CountIf(ReportList![A3:A200], "=" & TxtBx2.Value) + 1, 3)))
    Else
    End If
End Sub

My wish is to select a check box which then places the appropriate code in textbox2. This will then look for the highest number used for the selected section and adds 1 for help organise the Bin No. in sequence.

Any assistence will be appreciated.

THANKS
Report-Test.xlsm
0
Comment
Question by:user2073
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 37746170
That appears to equate to:

Private Sub TxtBx2_Change()
    Select Case TxtBx2
        case "MD", "SFC", "DOM"
        Me.TxtBx1.Value = Me.TxtBx2.Text & Format(Application.CountIf(Sheets("ReportList").Range("A3:A200"), TxtBx2.Value) + 1, "000")
    End Select
End Sub

Open in new window

0
 

Author Comment

by:user2073
ID: 37746417
Thanks for the quick responce. Works great but also need the number to increase by 1 for the case selections each time a record is saved. eg.
1st MD record should be MD001
2nd MD record becomes MD002 and so on.
1st SFC record should be SFC001
2nd SFC record becomes SFC002 and so on.
I hope this provides a little more clarity. See the "RED" Practice Area for examples.

Thanks
0
 
LVL 85

Accepted Solution

by:
Rory Archibald earned 2000 total points
ID: 37746464
Ah - small change:
Private Sub TxtBx2_Change()
    Select Case TxtBx2
        Case "MD", "SFC", "DOM"
        Me.TxtBx1.Value = Me.TxtBx2.Text & Format(Application.CountIf(Sheets("ReportList").Range("A3:A200"), TxtBx2.Value & "*") + 1, "000")
    End Select
End Sub

Open in new window


Note: you might want to use a combobox to provide the valid values for the MD, SFC etc.
0
 

Author Closing Comment

by:user2073
ID: 37746538
Great result many thanks for you assistence.
Keep up this fabulous service.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article helps those who get the 0xc004d307 error when trying to rearm (reset the license) Office 2013 in a Virtual Desktop Infrastructure (VDI) and/or those trying to prep the master image for Microsoft Key Management (KMS) activation. (i.e.- C…
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

597 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question