2016-10-06 2 views
0

아래 코드는 S 및 T 셀이 비어 있는지 확인합니다. 셀이 비어 있으면 텍스트가 U 열로 이동하여 비워 둘 수 없습니다. 내 문제는 셀이 한 번에 한 문자열을 취할 수있다, 나는 단일 셀에서 문자열을 연결하는 방법을 찾고있다. 도와주세요. 감사.vba를 사용하여 Excel 시트의 셀에 여러 문자열 값을 추가하는 방법

내 코드 :

 For pos2 = 1 To .UsedRange.Rows.Count + 1 Step 1 

      If (IsEmpty(.Cells(pos2, "S").Value) = True) Then 
       .Cells(pos2, "U").Value = "Description can't be blank" 
      End If 

      If (IsEmpty(.Cells(pos2, "T").Value) = True) Then 
       .Cells(pos2, "U").Value = "Criteria can't be blank" 
      End If 
     Next pos2 

답변

0

는 열 "U"에 기록 할 오류의 유형을 저장하기 :

Dim ErrStr  As String 

With Sheets("Sheet1") 

    For pos2 = 1 To .UsedRange.Rows.Count + 1 Step 1 
     ErrStr = "" ' reset the error string for each row 

     If IsEmpty(.Cells(pos2, "S").Value) Then 
      ErrStr = "Description can't be blank" 
     End If 

     If IsEmpty(.Cells(pos2, "T").Value) Then 
      ' just to make it clearer 
      If ErrStr <> "" Then 
       ErrStr = ErrStr & " ; " 
      End If 

      ErrStr = ErrStr & "Criteria can't be blank" 
     End If 

     .Cells(pos2, "U").Value = ErrStr 
    Next pos2 

End With 
+0

이 도와 주셔서 너무 감사드립니다. :) –

+0

@DeekshaGaur 환영합니다. 답으로 표시해주세요. –

-1

간단히 오히려 세포에 직접 작성하는 것보다, 문자열 변수에 &

같은
.Cells(pos2, "U").Value = .Cells(pos2, "U").Value & "Criteria can't be blank" 
0

스토어 문자열을 사용합니다. 같은 : 당신은 String을 사용할 수 있습니다

Dim strErrors as string 

    For pos2 = 1 To .UsedRange.Rows.Count + 1 Step 1 

     If (IsEmpty(.Cells(pos2, "S").Value) = True) Then 
      strErrors = "Description can't be blank. " 
     End If 

     If (IsEmpty(.Cells(pos2, "T").Value) = True) Then 
      strErrors = strErrors & "Criteria can't be blank" 
     End If 
     .cells(pos2, "U").value = strErrors 
    Next pos2 
관련 문제