1. 程式人生 > >幾種用EXCEL實現字串的"顛倒"的方法

幾種用EXCEL實現字串的"顛倒"的方法

Reverse text string with formula in Excel

Hot
Amazing! Using Tabs in Excel like Firefox, Chrome, Internet Explore 10!

In Excel, you can use a formula to reverse text string. For example, there are some text string as shown as below in Excel:

Step 1. Type this formula =IF(LEN(A1)<1,"",MID(A1,LEN(A1),1))&IF(LEN(A1)<2,"",MID(A1,LEN(A1)-1,1))&IF(LEN(A1)<3,"",MID(A1,LEN(A1)-2,1))&IF(LEN(A1)<4,"",MID(A1,LEN(A1)-3,1))&IF(LEN(A1)<5,"",MID(A1,LEN(A1)-4,1))

into B1, and then press Enter button. See screenshot:

Step 2. Copy this formula to other cells by dragging the bottom right corner of the Cell B1. See screenshot:

Note:

1. In this case, each of text string has five characters, so here the formula has five sections. If the text string has six characters, you need to add &IF(LEN(A1)<6,"",MID(A1,LEN(A1)-5,1)) 

to the end of the formula.

2. If each text string has a different number of characters in the column, you cannot drag the bottom right corner to copy the formula, you need to type the different formulas one by one.

arrow blue right bubble Reverse text string with VBA

Hot
Amazing! Using Tabs in Excel like Firefox, Chrome, Internet Explore 10!

Supposing you have a range of text strings which you want to reverse, such as “add leading zeros in Excel” to “lecxE ni sorez gnidael dda”. You can reverse the text with following steps:

1. Hold down the ALT + F11 keys, and it opens the Microsoft Visual Basic for Applications window.

2. Click Insert > Module, and paste the following macro in the Modulewindow.

Sub ReverseText()
'Updateby20131128
Dim Rng As Range
Dim WorkRng As Range

On Error Resume Next
xTitleId = "KutoolsforExcel"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)

For Each Rng In WorkRng
  xValue = Rng.Value
  xLen = VBA.Len(xValue)
  xOut = ""
  
  For i = 1 To xLen
    getChar = VBA.Right(xValue, 1)
    xValue = VBA.Left(xValue, xLen - i)
    xOut = xOut & getChar
  Next
  
  Rng.Value = xOut
Next

End Sub


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 SubReverseText() 'Updateby20131128 DimRngAsRange DimWorkRngAsRange OnErrorResume Next xTitleId = "KutoolsforExcel" SetWorkRng = Application.Selection SetWorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8) ForEachRng InWorkRng xValue = Rng.Value xLen = VBA.Len(xValue) xOut = "" Fori = 1 ToxLen getChar = VBA.Right(xValue, 1) xValue = VBA.Left(xValue, xLen - i) xOut = xOut & getChar Next Rng.Value = xOut Next EndSub

3. Then press F5, a dialog is displayed on the screen, and you need select a range to work with. See screenshot:

4. And then press OK, and all the text strings have been reversed. See screenshot:

arrow blue right bubble Reverse words separated by interval symbol with VBA

If you have a list of cell words which are separated by commas as this “teacher, doctor, student, worker, driver”, and you want to reverse the words order like this “drive, worker, student, doctor, teacher”. You can also use follow VBA to solve it.

1. Hold down the ALT + F11 keys, and it opens the Microsoft Visual Basic for Applications window.

2. Click Insert > Module, and paste the following macro in the Module window.

Sub ReverseWord()
'Updateby20131128
Dim Rng As Range
Dim WorkRng As Range
Dim Sigh As String
On Error Resume Next
xTitleId = "KutoolsforExcel"

Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
Sigh = Application.InputBox("Symbol interval", xTitleId, ",", Type:=2)

For Each Rng In WorkRng

strList = VBA.Split(Rng.Value, Sigh)
xOut = ""
For i = UBound(strList) To 0 Step -1
xOut = xOut & strList(i) & Sigh
Next
Rng.Value = xOut
Next
End Sub


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 SubReverseWord() 'Updateby20131128 DimRngAsRange DimWorkRngAsRange DimSighAsString OnErrorResume Next xTitleId = "KutoolsforExcel" SetWorkRng = Application.Selection SetWorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8) Sigh = Application.InputBox("Symbol interval", xTitleId, ",", Type:=2) ForEachRng InWorkRng strList = VBA.Split(Rng.Value, Sigh) xOut = "" Fori = UBound(strList) To0Step-1 xOut = xOut & strList(i) & Sigh Next Rng.Value = xOut Next

相關推薦

EXCEL實現字串的"顛倒"的方法

Reverse text string with formula in Excel Amazing! Using Tabs in Excel like Firefox, Chrome, Internet Explore 10! In Excel, you can use a formula

C#中常用的處理字串方法總結

主要有以下幾種: string[i]所獲得的元素是隻讀的。 string.ToCharArray() (把string獲得一個可寫的字元陣列) string.Replace(old, new)(將字串中指定字元或者子字串做相應的替換) string.ToLower

Tab的實現方法

pager rdf add htm transacti 圖片 post tle top 轉載請註明出處,謝謝! 學了這久Android,今天來總結一下幾種Tab的實現方法 實現方法一: ViewPage來實現 首先創建一個top.xml布局和一個bottom

c/c++中字串轉整形的方法

1.自己寫一個函式(c/c++) #include <stdio.h> #include <assert.h> /*  my string to integer function  */ int myfun(char *str){ int i =

python一classmethod實現單例模式方法的探討

初步實現程式碼如下: class Singleton(object): instance = None def __init__(self): pass @classmethod def get_instance(cls):

作橫向導航欄的方法

頁面 研究 title 導航 float alt idt bsp 廣泛 導航欄每個網站基本都有,形式也很多樣,其中應用最多最廣泛也是最常見的就是橫向導航欄。 今天就說以下幾種導航欄的形式。下面就給某個大學官網寫個導航欄。 首先第一種就是用應用的

Mat 的初始化和賦值方法

cto 轉換 -m mat tro sha 數據 return main 這幾天用到了由cv::Point3f和std::vector<float>到cv::Mat數據類型的轉換。本質上就是換一下容器。今晚做個小總結。 由Point3f 到 Mat 有兩種方法,

仿照SpringMVC實現字串方法對映

預備知識:註解,反射,spring基礎,SpringContextAware,SpringMVC實現原理 需求 輸入一個字串(稱因子名)陣列,陣列的長度不固定,每個字串代表一個業務單元(稱因子),因子是高度可擴充套件的。 輸出所有因子名與因子輸出的鍵值對。 輸入引數示例: {

設計模式之單例模式【內附物件例項化方式、實現執行緒安全方式】

繼續來複習常用的設計模式-單例模式,順便回憶一下執行緒安全的幾種實現方式。 一、什麼是單例模式 單例模式,簡單常用的一種設計模式,也很好的體現了程式碼控制物件在記憶體數量的一種方式,主要分2種實現方式: ①餓漢式,執行緒安全 ②懶漢式,執行緒不安全(新增鎖機制,可以實現執行緒安全)

[轉載]Scikit-learn介紹常用的特征選擇方法

valid 好的 多重 variable 統計學 助理 相關性 sele 不出 #### [轉載]原文地址:http://dataunion.org/14072.html 特征選擇(排序)對於數據科學家、機器學習從業者來說非常重要。好的特征選擇能夠提升模型的性能,更能幫助我

總結判斷RecyclerView到達底部的方法

今日科技快訊 近日,工信部旗下的寬頻發展聯盟給出了《中國寬頻速率狀況》2018年第三季度的報告:第三季度我國固定寬頻平均下載速度是3.12MB/s,上海、北京、江蘇名列前三;全國網速最快的城市,上海市依然位列第一,而北京市、南京市緊隨其後;三大運營商平均固網寬頻速度,其

hash.go- hash 函式實現

介面定義 type Hash interface {   // 嵌入了 io.Writer 介面    // 向執行中的 hash 加入更多資料 &nbs

遍歷陣列的常用方法

1.最傳統方法 for迴圈 var arr = ["first","second","third","fourth",3,5,8]; for(var i = 0; i < arr.length;i++){ console.log(arr[i]); } /

安卓-檢視SHA1和MD5的方法

安卓-幾種檢視SHA1和MD5的方法 1、獲取apk的sha1和md5 為了避免註冊時弄錯簽名,建議直接用打包出來的apk檢視簽名,具體如下: 1) 將apk修改後綴為 .rar檔案後解壓; 2) 進入解壓後的META-INF目錄,該目錄下會存在檔案CERT.R

java排序簡單實現(快速排序,氣泡排序,直接插入排序)

package Test; import com.alibaba.fastjson.JSONObject; public class Test { static int[] arrays = new int[] { 3, 10, 11, 1, 8, 2, 9, 4 }; // index

修改Linux主機名的方法

在安裝一些系統時,需要修改hostname,比如安裝Hadoop時需要修改主機名,而且主機名不能包含下劃線。 實際上,主機名分三種(命令hostnamectl或hostnamectl status可檢視三種主機名): 1) “pretty”主機名,UTF8格式的主機名,這

Python Numpy 100題實驗(九):標準化演算法實現

單獨把這幾道題目拿出來,歸為一類吧,都是標準化演算法。 本講的主要內容: Z-Score標準化演算法 Min-Max標準化演算法 應用L2正規化標準化資料 使用Z-Score標準化演算法對資料進行標準化處理 首先給出Z-Score標準化公式: Z=X−mea

定時器和延時方法

一、三種常用的定時器 1、Handler類的postDelayed方法: Handler mHandler = new Handler(); Runnable r = new Runnable() {

過的微控制器比較

 微控制器對於很多人並不陌生,在學校的時候就需要用到開發板,參與實際專案之後,很多地方也需要用到微控制器,下面對幾種常見的微控制器做一下比較,希望對初學者提供幫助。 51系列微控制器  用過比較多的就是STC微控制器,優點就是價格便宜,開發簡單,主要應用於對速度、功

3. 排序通常有多種演算法,如氣泡排序、插入排序、選擇排序、希爾排序、歸併排序、快速排序,請選擇任意2java實現 [分值:20] 您的回答:(空) (簡答題需要人工評分)

3. 排序通常有多種演算法,如氣泡排序、插入排序、選擇排序、希爾排序、歸併排序、快速排序,請選擇任意2種用java實現  [分值:20] 您的回答:(空)  (簡答題需要人工評分) package com.interview; /** * 各種排序演算法 */