아래 코드는 문자열이 작을 때 다른 워크 시트에서 셀을 찾기 위해 완벽하게 작동하지만 큰 텍스트 문자열은 오류를 발생시킵니다. 오류가 발생했을 때 VBA 창을 열지 않고 단지 MsgBox
을 제공하기 위해 오류 처리를 시도했습니다.더 큰 255자를 포함하는 셀 찾기
아무도 도와 주실 수 있습니다. 많은 문자가있는 셀을 찾거나 가능하지 않은 경우 과 같이 말하면서 오류 처리기를 넣으시면을 검색 할 수 있습니다.
코드의 역할은 각 셀에 텍스트가있는 셀 범위입니다. 해당 셀 또는 오른쪽의 셀 2 열을 클릭 한 다음 FIND
단추를 클릭하여 다음 워크 시트에서 동일한 셀 값을 찾을 수 있습니다. 모든 셀은 고유합니다. 당신을 또한
value = ActiveCell.Offset(, -2) 'Get the value of the selected Cell
If Len(value) > 255 Then
MsgBox "Text in cell " & CStr(ActiveCell.Address) & " is too long", vbOKOnly, "Search Text Too Long"
Exit Sub
End If
: 가치
당신이 할당 한 각 문 다음에이 추가 값을 :
Sub Find_Cell()
Dim NA As Worksheet
Set NA = Worksheets("Notes Analysis")
LastRow = NA.Cells(Rows.Count, 2).End(xlUp).Row
On Error Resume Next
If Not Intersect(ActiveCell, Range("G19:G" & LastRow)) Is Nothing Then
Dim value As String 'Declare a string
value = ActiveCell.Offset(, -2) 'Get the value of the selected Cell
Dim ws As Worksheet
'ws is the worksheet from we are searching the value
'You have to change myWorkSheetName for you worksheet name
Set ws = ThisWorkbook.Worksheets("DEBT_SALE_ACTIVITY")
ws.Activate
Dim c As Range 'Declare a cell
Set c = ws.Cells.Find(value, LookIn:=xlValues) 'Search the value
If Not c Is Nothing Then 'If value found
c.Activate 'Activate the cell, select it
Else
MsgBox "Not found" 'shows a message "Not Found"
End If
Else
If Not Intersect(ActiveCell, Range("E19:E" & LastRow)) Is Nothing Then
Dim value2 As String 'Declare a string
value2 = ActiveCell 'Get the value of the selected Cell
Dim ws2 As Worksheet
'ws is the worksheet from we are searching the value
'You have to change myWorkSheetName for you worksheet name
Set ws2 = ThisWorkbook.Worksheets("DEBT_SALE_ACTIVITY")
ws2.Activate
Dim c2 As Range 'Declare a cell
Set c2 = ws2.Cells.Find(value2, LookIn:=xlValues) 'Search the value
If Not c2 Is Nothing Then 'If value found
c2.Activate 'Activate the cell, select it
Else
MsgBox "Not found" 'shows a message "Not Found"
End If
Else
MsgBox "Select an Account Note"
End If 'end the If for if active cell is in our notes
End If 'end the If for if active cell is in Account note
End Sub
을,하지만 당신은'당신의 두 블록 코드의 모두'값 = ActiveCell.EntireRow.Range ("E1")를 사용할 수 있습니다
코드는 다음과 같이 작동합니다 따라서 두 블록을 하나의 블록으로 결합합니다. – YowE3K
위대한 아이디어, 나는 내가 갈 수 있다는 것을 깨닫지 못했다. 그러나 그 충고가 실제로 도움이된다. 그런 식으로 현재 셀이 행의 모든 셀에있을 수 있지만 E 열의 셀을 검색하고 코드의 크기를 반으로 줄입니다. 감사합니다. –