Code advice to change number 1 to 2 in a specific column & its format

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,736
Office Version
  1. 2007
Platform
  1. Windows
Morning,

I am wanting to change a value of 1 to a 2 in two sets of numbers.

The column in question is J
The worksheet is called DATABASE
Range is J6 then down the page
Number format comprising of two sets of numbers in the cell is as example 987652 - 758651

The important part is the last number for each set of which must be a 1
As you can see in the above example the first set ends in 2 "987652" so once the code has been run it should become "987651"

Some info for you.

Some cells will have the correct format so this cell should be ignored.
Some cells will have both number sets ending in a 2 so both need to be changed to a 1
Some cells will only have a 2 in the second set of numbers.

Whilst im thinking about it the inserted values in each cell must be like this.
Fit set of numbers will always consist of 6 numbers followed by a space then - then a space then 6 numbers where both sets end with a 1

Is there something we can do to change the entered value should the user have used 2 spaces as opposed to 1 or the like.

Many thanks
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
OK
Runing code #9 it kind of works but with issues BUT now no run time error.
This is what i see happen when i test.

N/A becomes N/A1

2232433421 becomes 223241

341152 - 433356 becomes 341151 - 341151

MANUAL CUT becomes MANU1

The items in question that i need changing has tis issue.
Example

123456 - 654321 the second set of numbers are deleted & replaced with the same set of first number so 123456 - 123456

Like wise 999999 - 555555 becomes 999999 - 999999
 
Upvote 0
HI
Hope this covers all
VBA Code:
Private Sub CommandButton1_Click()
    Dim a, x
    Dim i&
    With Sheets("DATABASE")
        a = .Cells(6, 11).Resize(.Cells(Rows.Count, 11).End(xlUp).Row - 5).Value2
        For i = 1 To UBound(a)
            If a(i, 1) <> "" Or a(i, 1) <> "N/A" Then
                On Error Resume Next
                x = Split(a(i, 1), " - ")
                If Len(x(0)) = 6 Then
                    If Right(x(0), 1) = 2 Then x(0) = Left(x(0), 5) & 1
                End If
                    If Len(x(1)) = 6 Then
                        If Right(x(1), 1) = 2 Then x(1) = Left(x(1), 5) & 1
                    End If
            End If
            a(i, 1) = Join(x, " - ")
        Next
        Cells(6, 11).Resize(UBound(a)) = a
    End With
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,223,893
Messages
6,175,242
Members
452,623
Latest member
russelllowellpercy

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