search
HomeTopicsexcelSummary of usage of SUBSTITUTE function in Excel

本篇文章给大家带来了关于excel的相关知识,其中主要介绍了SUBSTITUTE函数的相关问题,该函数是Excel最常用的文本函数之一,在数据分析过程中,常用于字符串的整理和清洗,下面一起来看一下,希望对大家有帮助。

Summary of usage of SUBSTITUTE function in Excel

相关学习推荐:excel教程

SUBSTITUTE函数的基础语法是:

SUBSTITUTE(要替换的文本,旧文本,新文本,[替换第几个])

最后一个参数,[替换第几个], 是可以省略的。

举几个小栗子,和大家分享下SUBSTITUTE函数的常用技巧和套路。

1,将数据中的某个值替换为另一个值

比如将B列数据里的二班,替换为一班。

C2输入公式,并向下复制填充:

=SUBSTITUTE(B2,"二班","一班")

Summary of usage of SUBSTITUTE function in Excel

这里没啥好解释的了,就是将B列中单元格中的“二班”全部替换为“一班”。

2,隐藏手机号的中间5位

C2输入公式,并向下复制填充:

=SUBSTITUTE(B2,MID(B2,4,5),"*****")

Summary of usage of SUBSTITUTE function in Excel

先使用MID函数取得B列号码中的中间五位,再用字符串“*****”替换掉这部分内容。

3,对含单位的数据求和

B7输入公式:

=SUMPRODUCT(SUBSTITUTE(B2:B6,"人",)*1)

Summary of usage of SUBSTITUTE function in Excel

先用SUBSTITUTE替换掉B列单元格中的“人”,得到文本型数字,乘以1后转换成可以计算的数值,再用SUMPRODUCT函数进行求和。

4,数据分列,将B列数据按顿号进行分列

C2单元格输入公式横向拖动,并向下复制填充。

=TRIM(MID(SUBSTITUTE($B2,"、",REPT(" ",100)),COLUMN(A1)*100-99,100))

Summary of usage of SUBSTITUTE function in Excel

REPT(” “,100)

先使用REPT函数,将空格重复100次,得到100个空格。

SUBSTITUTE($B2,”、”,REPT(” “,100))

使用SUBSTITUTE函数将姓名中的的间隔符号顿号替换为100个空格。

MID(SUBSTITUTE($B2,”、”,REPT(” “,100)),COLUMN(A1)*100-99,100)

再使用MID函数,依次从带有空格的新字符串中的第1、第101、第201位……截取长度为100的字符。

这样得到的字符串是带有多余空格的,因此再使用TRIM函数将多余空格删除掉。

5,混合文本中,计算人数个数

Summary of usage of SUBSTITUTE function in Excel

B2公式:

=LEN(A2)-LEN(SUBSTITUTE(A2,"、",))+1

LEN(A2)取得A2字符串的长度。

LEN(SUBSTITUTE(A2,”、”,))+1,替换掉人名之间的间隔符,也就是顿号,再用LEN计算该值的长度,最后加1,是因为最后一个人名没有顿号。

用A2数值原有的长度减去被替换掉人名之间间隔符的长度,也就是人名的个数。

6,混合文本中,计算数值最大值。

Summary of usage of SUBSTITUTE function in Excel

B2数组公式:

=MAX((SUBSTITUTE(A2,ROW($1:$98),)<>A2)*ROW(1:98))

SUBSTITUTE(A2,ROW($1:$98),)A2

依次将数值1到98从A2替换为空,然后把替换后的结果和被替换值(1-98)进行比较 ,如果不相等,则证明A2中存在该数值。

最后将上述部分公式的运算结果,也就是逻辑值TRUE和FALSE,乘以被替换的值(1-98),用MAX函数从中取得最大值。

7,计算某个值在某个范围的最大连续次数

Summary of usage of SUBSTITUTE function in Excel

B2数组公式:

=MAX((SUBSTITUTE(PHONETIC(A2:A9),REPT("A",ROW(1:9)),)<>PHONETIC(A2:A9))*ROW(1:9))

PHONETIC(A2:A9)

将A2:A9的文本值黏合成一个值,以便SUBSTITUTE函数进行操作。

REPT(“A”,ROW(1:9))

把“A”重复1到9次。

SUBSTITUTE(PHONETIC(A2:A9),REPT(“A”,ROW(1:9)),)<>PHONETIC(A2:A9)

思路回到示例6,SUBSTITUTE函数将REPT函数的运算结果,在PHONETIC函数的运算结果里替换掉,然后和PHONETIC函数的原值进行比较。如果后者存在替换值,则被替换掉,此时和原值不相等,返回FALSE,否则返回TRUE。

最后依然把上述公式返回的逻辑值TRUE和FALSE,分别乘以ROW(1:9),用MAX函数从中取得最大值。

相关学习推荐:excel教程

The above is the detailed content of Summary of usage of SUBSTITUTE function in Excel. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:Excel Home. If there is any infringement, please contact admin@php.cn delete
MEDIAN formula in Excel - practical examplesMEDIAN formula in Excel - practical examplesApr 11, 2025 pm 12:08 PM

This tutorial explains how to calculate the median of numerical data in Excel using the MEDIAN function. The median, a key measure of central tendency, identifies the middle value in a dataset, offering a more robust representation of central tenden

Google Spreadsheet COUNTIF function with formula examplesGoogle Spreadsheet COUNTIF function with formula examplesApr 11, 2025 pm 12:03 PM

Master Google Sheets COUNTIF: A Comprehensive Guide This guide explores the versatile COUNTIF function in Google Sheets, demonstrating its applications beyond simple cell counting. We'll cover various scenarios, from exact and partial matches to han

Excel shared workbook: How to share Excel file for multiple usersExcel shared workbook: How to share Excel file for multiple usersApr 11, 2025 am 11:58 AM

This tutorial provides a comprehensive guide to sharing Excel workbooks, covering various methods, access control, and conflict resolution. Modern Excel versions (2010, 2013, 2016, and later) simplify collaborative editing, eliminating the need to m

How to convert Excel to JPG - save .xls or .xlsx as image fileHow to convert Excel to JPG - save .xls or .xlsx as image fileApr 11, 2025 am 11:31 AM

This tutorial explores various methods for converting .xls files to .jpg images, encompassing both built-in Windows tools and free online converters. Need to create a presentation, share spreadsheet data securely, or design a document? Converting yo

Excel names and named ranges: how to define and use in formulasExcel names and named ranges: how to define and use in formulasApr 11, 2025 am 11:13 AM

This tutorial clarifies the function of Excel names and demonstrates how to define names for cells, ranges, constants, or formulas. It also covers editing, filtering, and deleting defined names. Excel names, while incredibly useful, are often overlo

Standard deviation Excel: functions and formula examplesStandard deviation Excel: functions and formula examplesApr 11, 2025 am 11:01 AM

This tutorial clarifies the distinction between standard deviation and standard error of the mean, guiding you on the optimal Excel functions for standard deviation calculations. In descriptive statistics, the mean and standard deviation are intrinsi

Square root in Excel: SQRT function and other waysSquare root in Excel: SQRT function and other waysApr 11, 2025 am 10:34 AM

This Excel tutorial demonstrates how to calculate square roots and nth roots. Finding the square root is a common mathematical operation, and Excel offers several methods. Methods for Calculating Square Roots in Excel: Using the SQRT Function: The

Google Sheets basics: Learn how to work with Google SpreadsheetsGoogle Sheets basics: Learn how to work with Google SpreadsheetsApr 11, 2025 am 10:23 AM

Unlock the Power of Google Sheets: A Beginner's Guide This tutorial introduces the fundamentals of Google Sheets, a powerful and versatile alternative to MS Excel. Learn how to effortlessly manage spreadsheets, leverage key features, and collaborate

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool