如何使用IF语句从字符串开头删除零

时间:2018-11-06 20:22:32

标签: excel vba excel-vba

在AJ列中,有一个行情清单:

02382 HK
00700 HK
0WI GR

如果最后两个字母是HK,我想删除前面的零。所以上面应该是:

2382 HK
700 HK
0WI GR

感谢您的帮助

2 个答案:

答案 0 :(得分:1)

可以在没有VBA的情况下实现:

 =IF(RIGHT(AJ2,2)="HK",1*LEFT(AJ2,FIND(" ",AJ2))&" HK",AJ2)

答案 1 :(得分:0)

我建议使用此功能

// @material-ui/icons
import Dashboard from "@material-ui/icons/Dashboard";
import Logs from "@material-ui/icons/Assignment";

import Index from "./views/Index";
import LoggingPage from "./views/Logging";

const dashboardRoutes = [
{
path: "/",
sidebarName: "Home",
navbarName: "Index",
icon: Dashboard,
component: Index
},
{
path: "/logging",
sidebarName: "Logs",
navbarName: "Logs",
icon: Logs,
component: LoggingPage
},
{ redirect: true, path: "/", to: "/dashboard" }
];

export default dashboardRoutes;

这也适用于Function RemoveIt(s As String) As String If Right(s, 2) = "HK" Then Dim i As Long Dim l As Long l = Len(s) For i = 1 To l If Left(s, 1) = "0" Then s = Right(s, Len(s) - 1) Else Exit For End If Next i End If RemoveIt = s End Function 002382HK之类的字符串