开发者

Excel 2010 VBA - using the Like operator to copy cell values

开发者 https://www.devze.com 2023-04-06 08:38 出处:网络
I want to copy the contents of a cell only if the cell conta开发者_运维技巧ins times in the following format: 9:00-5:00pm. (The cell may contain abbreviations such as \"N/A\", \"RDO\", \"Leave\" etc.

I want to copy the contents of a cell only if the cell conta开发者_运维技巧ins times in the following format: 9:00-5:00pm. (The cell may contain abbreviations such as "N/A", "RDO", "Leave" etc. I tried this:

If Worksheets(2).Cells(R, c).Value Like "*-*" Then

Worksheets(26).Cells(x, c).Value = Worksheets(2).Cells(R, c).Value
end if

but it doesn't work properly. I'm experience with VBA in Excel, but I've never used the LIKE operator before.


To look for a - only;

"*-*"

Alternatively you could be stricter;

if x like "#*:##-#*:##[ap]m"


the Like part of your code is fine. to prove it, run this code fragment:

If "9:00-5:00pm" Like "*-*" Then
    MsgBox "True"
End If

the problem must lie elsewhere. post some details of how it doesn't work for you...

0

精彩评论

暂无评论...
验证码 换一张
取 消