如何在excel中的每个单词之前插入数字 [英] how to insert numbers before every word in excel

查看:147
本文介绍了如何在excel中的每个单词之前插入数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

http://imgur.com/ekrjv0D

请检查以上图片。有没有办法在工作表中的每个单词之前插入数字。

我有一个这样的表:

Hi please check above image. Is there any way to insert number before each word in worksheet.
I have a table like this:

╔════════════╦═══════╗
║     Colour ║       ║
╠════════════╬═══════╣
║            ║ Blue  ║
╠════════════╬═══════╣
║            ║ red   ║
╠════════════╬═══════╣
║            ║ pink  ║
╠════════════╬═══════╣
║     Fruidm ║       ║
╠════════════╬═══════╣
║            ║ mango ║
╠════════════╬═══════╣
║            ║ Apple ║
╚════════════╩═══════╝

输出应该是这样的:

╔══════════════╦═════════╗
║     1/Colour ║         ║
╠══════════════╬═════════╣
║              ║ 2/Blue  ║
╠══════════════╬═════════╣
║              ║ 3/red   ║
╠══════════════╬═════════╣
║              ║ 4/pink  ║
╠══════════════╬═════════╣
║     5/Fruidm ║         ║
╠══════════════╬═════════╣
║              ║ 6/mango ║
╠══════════════╬═════════╣
║              ║ 7/Apple ║
╚══════════════╩═════════╝

等等这个:

╔══════════════╦═════════╗
║     1/Colour ║         ║
╠══════════════╬═════════╣
║              ║ 3/Blue  ║
╠══════════════╬═════════╣
║              ║ 4/red   ║
╠══════════════╬═════════╣
║              ║ 5/pink  ║
╠══════════════╬═════════╣
║     2/Fruidm ║         ║
╠══════════════╬═════════╣
║              ║ 6/mango ║
╠══════════════╬═════════╣
║              ║ 7/Apple ║
╚══════════════╩═════════╝


推荐答案

已发布的另一个附加变体:

another additional variant to already posted:

Sub test()
    Dim cl As Range, i&
    Set cl = Cells.Find("*")
    For i = 1 To WorksheetFunction.CountA(Cells)
        If Not cl Is Nothing Then
            cl.Value2 = i & "/" & cl.Value2
            Set cl = Cells.FindNext(cl)
        Else
            Exit For
        End If
    Next i
End Sub

针对其他问题进行更新:

updated against additional question:


有没有办法删除数字和斜杠开头每个单词

Is there anyway to remove back the numbers and slash at the beginning of each word

你可以使用这个:

Sub test2()
   Dim n&, r As Range:  n = 1
   For Each r In ActiveSheet.UsedRange
      If r.Value2 Like "*/*" Then
         r.Value2 = Split(r.Value2, "/")(1)
         n = n + 1
      End If
   Next r
End Sub

这篇关于如何在excel中的每个单词之前插入数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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