简体   繁体   English

根据单元格值重命名工作表

[英]Rename sheet based on cell value

Can you help me to provide VBA code to rename all sheet based on call value available in A1 of each sheet but wanted to pick only 1st there word as sheet name 您能帮我提供VBA代码,以便根据每张图纸的A1中可用的调用值来重命名所有图纸吗,但只想选择第一个单词作为图纸名称

sub rename ()
    for each sht in thisworkbook.worksheets
        sht.name=sht.range("A1")
    next sht

This VBA is renaming all sheet but I want to capture only first three word from cell A1 此VBA重命名所有工作表,但我只想捕获单元格A1中的前三个单词

For eg. 例如。 "A1" = "Fund GQ Jan Q1 2019" so I need sheet name to be "Fund GQ Jan" "A1" = "Fund GQ Jan Q1 2019"因此我需要将工作表名称命名为“ 1月GQ基金”

A little manipulation with the String will help: 对String进行一些操作会有所帮助:

See the use of Left and Instr 查看LeftInstr的用法

Sub rename()

    For Each sht In ThisWorkbook.Worksheets
        sht.Name = Left(sht.Range("A1"), InStr(1, sht.Range("A1"), Split(sht.Range("A1"), " ")(3)) - 2)
    Next sht

End Sub

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM