转换成百分比

时间:2018-08-28 19:13:20

标签: excel excel-vba

我有一个带有文字和数字( public IEnumerable<Student> Get(Expression<Func<Student, bool>> expr = null, Func<IQueryable<Student>, IOrderedQueryable<Student>> orderBy = null, Func<IQueryable<Student>, IIncludableQueryable<Student, object>> includes = null) { var repo = _unitOfWork.GetRepository<Student>(); var students= repo.GetPagedList(expr, orderBy, includes) .Items; return students; } public void Main() { Get(expr: null, orderBy: orderBy => orderBy.OrderBy(mark => mark.Marks.OrderBy(curr => curr.CurrMark))); //over here i came across an error } public class Student { public int Id { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public ICollection<Mark> Marks { get; set; } } public class Mark { public int Id { get; set; } public int CurrMark { get; set; } public int StudentId { get; set; } public Student Student { get; set; } } )的单元格。 我只想将数字123更改为百分比(abc123)。 有可能吗? 谢谢。

1 个答案:

答案 0 :(得分:1)

对于您的特定示例,您可以使用SUBSTITUTE函数SUBSTITUTE(Text,Old_text,New_text)

文本为必填。文本或对包含要替换字符的文本的单元格的引用。

旧文本是必需的。您要替换的文本。

新文本是必需的。您要替换为old_text的文本。

尝试一下:

abc123放在单元格A1中 在单元格A2中,此公式:

=SUBSTITUTE(A1,RIGHT(A1,LEN(A1)-MIN(SEARCH({0,1,2,3,4,5,6,7,8,9},A1&"0123456789"))+1),RIGHT(A1,LEN(A1)-MIN(SEARCH({0,1,2,3,4,5,6,7,8,9},A1&"0123456789"))+1)/10&"%")

文本: A1

旧文本: RIGHT(A1,LEN(A1)-MIN(SEARCH({0,1,2,3,4,5,6,7,8,9},A1&"0123456789"))+1)

新文本: RIGHT(A1,LEN(A1)-MIN(SEARCH({0,1,2,3,4,5,6,7,8,9},A1&"0123456789"))+1)/10&"%"

RIGHT(A1,LEN(A1)-MIN(SEARCH({0,1,2,3,4,5,6,7,8,9},A1&"0123456789"))+1)提取数字。您可以使用数字/1000进行任何操作,还可以使用函数ROUND

ROUND(RIGHT(A1,LEN(A1)-MIN(SEARCH({0,1,2,3,4,5,6,7,8,9},A1&"0123456789"))+1)/1000,2) = 0.12

最终功能将是:

=SUBSTITUTE(A1,RIGHT(A1,LEN(A1)-MIN(SEARCH({0,1,2,3,4,5,6,7,8,9},A1&"0123456789"))+1),ROUND(RIGHT(A1,LEN(A1)-MIN(SEARCH({0,1,2,3,4,5,6,7,8,9},A1&"0123456789"))+1)/1000,2)&"%")