简体   繁体   English

如何使用 Excel 宏将部分字符串从特定单元格复制到另一个单元格?

[英]How to copy part of a string from a specific cell to another cell with Excel macros?

How do I copy part of a string in a cell to another cell?如何将单元格中的部分字符串复制到另一个单元格?

For example: In cell A1 it says Force: 2035N .例如:在单元格 A1 中显示Force: 2035N I want to copy only the 2035N part from it from A1 to B1.我只想将2035N部分从 A1 复制到 B1。 How do I do that?我怎么做?

I started looking a MID substring.我开始寻找 MID substring。 So something like:所以像:

a=Mid(ActiveSheet.Range(“A1”), 1 5)). 

But I'm completely new to VBA so I don't really know how to make it work.但我对 VBA 完全陌生,所以我真的不知道如何让它工作。

Edit: More info.编辑:更多信息。

What I want to copy我要复制的内容我要复制的内容

End result最终结果最终结果

I have a CSV file with lots of data in different rows.我有一个 CSV 文件,在不同的行中有很多数据。 I want to use a macro so I can sort all this data in a desired order and transpose it so I can just copy it to another excel file.我想使用一个宏,这样我就可以按所需的顺序对所有这些数据进行排序并转置它,这样我就可以将它复制到另一个 excel 文件中。

The characters from the whole string I want to copy from the original cell (let's say they are in cell A1-A7) are in bold (in the picture).我想从原始单元格中复制的整个字符串中的字符(假设它们在单元格 A1-A7 中)以粗体显示(在图片中)。 And this csv file is always in the same order and the characters are in the same place.而这个 csv 文件的顺序总是相同的,字符在同一个地方。

I want to copy the bold part of the cell from A1-A7 to for example B1-H1.我想将单元格的粗体部分从 A1-A7 复制到例如 B1-H1。

Try below sub.试试下面的子。

Sub SplitString()
    Dim str
    
    str = Split(Range("A1"), " ")
    
    Range("B1") = str(UBound(str))
    
End Sub

If you want to use formula only then try-如果您只想使用公式,请尝试-

=TRIM(MID(A1,SEARCH(" ",A1)+1,LEN(A1)))

在此处输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 VBA:如何从一个单元格复制一部分字符串,并用它替换另一单元格的一部分? - VBA: How to copy part of the string from one cell and replace part of another cell with it? 如何将一个单元格的内容复制到另一个单元格中的特定字符串 - How to copy contents of one cell to a specific string in another cell 如何使用 Powershell 从 excel 中的一个工作簿的特定单元格复制信息并将其粘贴到另一个工作簿的特定单元格? - How do I copy info from a specific cell from one workbook in excel and paste it to a specific cell to another workbook using Powershell? Excel VBA:从另一个工作簿循环中复制和粘贴特定单元格 - Excel VBA: Copy and Paste Specific Cell from Another Workbook Loop 选择并提取特定作为Excel单元格中字符串的一部分 - select and extract specific as part of a string in excel cell Excel:根据另一个单元格(字符串)删除部分单元格(字符串) - Excel: Remove part of cell (String) based on another cell (String) Excel:基于另一个工作表中的字符串匹配复制单元格信息 - Excel: Copy cell info based on string match from another sheet VBA,Excel宏:将单元格值复制到另一个工作表,偏移,重复直到找到空单元格 - VBA, Excel macros: copy cell value to another sheet, offset, repeat until finding an empty cell 从网站复制到 excel 中的特定单元格 - Copy from a website to a specific cell in excel 如果另一个单元格包含特定的文本字符串,则复制一个单元格 - Copy a cell if another cell contains a specific text string
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM