Share via

Add alpha character...

Anonymous
2018-02-26T01:59:52+00:00

I had one of the "community" help me with a problem in which he wrote a VB code for me. The first column was a part number in which a five digit number was entered (44141). My problem is I want to add an alpha to it which indicates a version of the part. Whenever I add it to the Table it no longer will add the number of parts to the sheet. I think its because its looking for only number values in the part number. This is the portion of the code I think needs to be changed.....any thoughts on how to proceed?

   Application.Volatile

    Set ws = rng.Parent

    With ws

        Set rngTemp = .Cells(rng.Row, 1)    'Assign range variable to the cell same row in Part# column

        If rngTemp.Value = "" Then          'If the cell in column A and on same row is blank

            Set rngTemp = rngTemp.End(xlUp) 'Move up to non blank cell containing the Part# and assign that cell to the range variable

        End If

        If IsNumeric(rngTemp) Then

            'If first Part# is deleted then rngTemp becomes the column header and will not be numeric and cause an error.

            TotUnits = rngTemp.Offset(0, 1).Value     'Assign the value in the Cell to right of Part# (#Full Units Required) to the Funtion

        Else

            TotUnits = 0    'Set to zero if first Part# is deleted

        End If

    End With

End Function

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

OssieMac 48,001 Reputation points Volunteer Moderator
2018-02-27T01:44:53+00:00

In Module1 edit the code as per the comments in bold italics in the example code below. (Delete the old line and insert the new line it its place).

Because you have placed an alpha on the end of the number it does not evaluate to a numeric to identify that it is not the column header so we will test the left 5 characters only to ensure they are numeric.

You will need to re-insert your column header (Total Boards Required) in cell E1.

Function TotUnits(rng As Range) As Long

    Dim ws As Worksheet

    Dim rngTemp As Range

    Application.Volatile

    Set ws = rng.Parent

    With ws

        Set rngTemp = .Cells(rng.Row, 1)    'Assign range variable to the cell same row in Part# column

        If rngTemp.Value = "" Then          'If the cell in column A and on same row is blank

            Set rngTemp = rngTemp.End(xlUp) 'Move up to non blank cell containing the Part# and assign that cell to the range variable

        End If

        'If IsNumeric(rngTemp) Then     'Delete this line of code

        If IsNumeric(Left(rngTemp, 5)) Then     'Replace deleted line with this line of code

            'If first Part# is deleted then rngTemp becomes the column header and will not be numeric and cause an error.

            TotUnits = rngTemp.Offset(0, 1).Value     'Assign the value in the Cell to right of Part# (#Full Units Required) to the Funtion

        Else

            TotUnits = 0    'Set to zero if first Part# is deleted

        End If

    End With

End Function

Was this answer helpful?

2 people found this answer helpful.
0 comments No comments

3 additional answers

Sort by: Most helpful
  1. Anonymous
    2018-02-28T01:24:16+00:00

    Aussie Mac to the rescue....worked perfectly...thanks again. I'll hopefully not need to make and more changes to this part of the programing. You've been a big help and I've started to see that there's been a lot of changes since I last looked into Excel. Again thanks.

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2018-02-26T14:12:26+00:00

    Good Morning Aussie Mac...I bet you had to think twice about becoming involved "again". I had added the alpha to the table and the programing brought up he components as hoped for. The problem exists when I try to use the Totals for the parts needed....

    Column E is the total boards required and it renders the correct value when the orginal table has just numeric numbers in column A. When I updated the table with "Alpha" then I get the above. Take the "Alpha" out and it works perfect again. That's why it appeared to me that the programing was looking for a "numeric" value only in column A.  As usual I'm grateful for any insight you can share...Thanks.

    Was this answer helpful?

    0 comments No comments
  3. OssieMac 48,001 Reputation points Volunteer Moderator
    2018-02-26T09:00:17+00:00

    It was I who answered your previous question. If you want to add an alpha character to the number then you need to edit the lookup table and add the records with the alpha characters because they become individual values for the Lookup to work..

    eg. if 44141 is now 44141A, 44141B  and 44141C then all the part numbers must be in the lookup table like the following screen shot.

    Was this answer helpful?

    0 comments No comments