目的是将这种字符串与特定值“INPR0002268”分开。意味着一旦你找到第一个零,字符串就应该打印“0002268”。 [英] The objective is to separate this kind of string from particular value "INPR0002268" means once you find 1st zero the string should print "0002268"

查看:81
本文介绍了目的是将这种字符串与特定值“INPR0002268”分开。意味着一旦你找到第一个零,字符串就应该打印“0002268”。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我试图从特定单元格中读取一个字符串,然后将该字符串从Zero on-wards中拆分并在另一个单元格中打印该值



Issue- >在本地窗口中,当我运行代码时,它显示正确的值0002268但是当我在另一个单元格中插入相同的值时显示2268。请让我知道可能的原因。



So i am trying to read a string from a particular cell and then split the string from Zero on-wards and print the value in another cell

Issue-> In the local window when i am running the code it is showing the correct value "0002268 " but when i insert the same value in another cell its showing "2268".Please let me know what can be possible reason.

Sub newid()

Dim FirstZero As Long
Dim Name As Variant

Sheet2.Activate

Columns("E:E").Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("E1").Value = "Orgnization ID"

Numberofrow = Cells(Rows.Count, 1).End(xlUp).Row

For i = 1 To Numberofrow

Y = Range("A1").Offset(i, 0).Value
Lengthofstring = Len(Y)

FirstZero = InStr(1, Y, 0)
Debug.Print FirstZero

Name = Right(Y, Lengthofstring - (FirstZero - 1))

Range("A1").Offset(i, 0).Offset(0, 4).Value = Name

Next i

End Sub





我尝试过:





What I have tried:

Sub newid()

Dim FirstZero As Long
Dim Name As Variant

Sheet2.Activate

Columns("E:E").Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("E1").Value = "Orgnization ID"

Numberofrow = Cells(Rows.Count, 1).End(xlUp).Row

For i = 1 To Numberofrow

Y = Range("A1").Offset(i, 0).Value
Lengthofstring = Len(Y)

FirstZero = InStr(1, Y, 0)
Debug.Print FirstZero

Name = Right(Y, Lengthofstring - (FirstZero - 1))

Range("A1").Offset(i, 0).Offset(0, 4).Value = Name

Next i

End Sub

推荐答案

因为它是一个数字 - 除非该列被格式化为Text,或者数字前面有引号,Excel会将其视为数字。并且数字没有前导零...

在引号前加0,Excel应将其视为文本。
Because it's a number - and unless the column is formatted as Text, or the number is preceded by a quote, Excel will treat it as a number. And numbers do not have leading zeros...
Prefix the first 0 with a quote and Excel should treat it as text.


这篇关于目的是将这种字符串与特定值“INPR0002268”分开。意味着一旦你找到第一个零,字符串就应该打印“0002268”。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆