简体   繁体   English

仅考虑单元格Excel-VBA中编写的内容的一部分

[英]Consider only part of what is written in a cell Excel-VBA

So in cell let's say "b1" I have a Data validation with the following (whatever is written after the date and a space is the Project name): 因此,在单元格中,让我们说“ b1”,我将进行以下数据验证(日期之后写的任何内容,项目名称都为空格):

05/01/2016 I like icecreams 2016/05/01我喜欢冰淇淋
05/01/2016 Project B: whatever 2016/05/01项目B:随便
12/01/2016 Project Me! 2016年12月1日为我计划!
18/01/2016 Hello world 2016/01/18你好世界
01/02/2016 I like chocolate 2016/01/02我喜欢巧克力
27/02/2016 Real business 27/02/2016真实的业务

I created a macro that checks the "b1" name and if it is equal it does something. 我创建了一个宏来检查“ b1”名称,如果它相等,它将执行某些操作。 My problem is that I recently added the Date to the data validation because I needed to ease the burden of knowing when the Project started. 我的问题是,我最近将日期添加到了数据验证中,因为我需要减轻知道项目何时开始的负担。

In my macros I have for example this variable: 在我的宏中,例如,有此变量:
projectname = Sheet1.Range("b1").Value 项目名称= Sheet1.Range(“ b1”)。Value

This variable no longer gets positive results because the Date is also in the Data validation. 由于日期也位于数据验证中,因此该变量不再获得肯定的结果。 I need something like only consider the right part after 11 characters of what is written in "b1". 我需要类似“ b1”中写出的11个字符之后才考虑正确的部分。
How can I change the way the variable is set up in Excel-VBA? 如何更改在Excel-VBA中设置变量的方式?

If the date is always going to be the 11 characters of dd/mm/yyyy plus the space then the variable assignment would be: 如果日期始终是dd / mm / yyyy的11个字符加上空格,则变量赋值为:

Dim strCellValue As String
Dim strProjectName As String

strCellValue = Sheet1.Range("b1").Value
strProjectName = Right$(strCellValue, Len(strCellValue) - 11)

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

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