2016-07-05 2 views
0

Excel 2010을 사용 중입니다.Excel 매크로 : 매크로를 사용하여 셀 값과 문자열 연결

문자열을 셀 값과 연결하는 데 사용되는 다음 매크로가 있습니다.

Sub Mac1() 
Dim cell As Range 
For Each cell In Range("D3", Range("D65536").End(xlUp)) 
    If cell.Value = "" Then 
     cell.Value = "" 
    Else 
     cell.Value = cell.Value & " Day" 
    End If 
Next 
End Sub 

: 내가 매크로를 실행할 때 Day이 각각 추가 된 문자열과 모든 시간을 얻기.

예상 결과는 셀이 비어있는 경우 셀과 연결될 문자열이 없으면 셀이 비어있는 경우 끝에 셀 값과 함께 한 번에 Day 문자열을 연결해야합니다.

답변

3

Try는 중첩 된 If 문자열이 이미 " Day"으로 끝나는 지 확인합니다.

Sub Mac1() 
    Dim cell As Range 

    With Worksheets("SHeet1") 'KNOW WHAT WORKSHEET YOU ARE ON!!!!!! 
     For Each cell In .Range("D3", .Range("D65536").End(xlUp)) 
      If CBool(Len(cell.Value)) Then 
       If Right(LCase(cell.Value), 4) <> " day" Then 
        cell.Value = cell.Value & " Day" 
       End If 
      End If 
     Next cell 
    End With 
End Sub 
+0

안녕하세요! 이 일을 도와주세요. https://stackoverflow.com/questions/38199207/excel-vba-function-calculate-secondsalso-counts-the-milliseconds-from-two-da – MAK