2012-11-11 3 views
3
1 
2 
3 
4 
. 
. 

그래서 일련 번호는 1-20에서 실행됩니다. 나는 상단에 숫자 "1"을 선택하고 전체 열을 검색하고 숫자 "9"를 찾고 싶습니다. 이 코드는 "rng"범위에 이름을 지정하지 않으면 작동합니다. 번호를 찾아서 선택합니다. 그러나 번호의 범위를 지정하면 코드가 작동을 멈 춥니 다. range 함수의 문제점은 무엇입니까? Dim rng as Range을 정의하면 나중에 "Set rng="을 정의 할 때 끝에서 ".Select" 또는 ".Copy" 확장자를 가질 수 없습니까? 나는 숫자 "20"내가 사용해야 아래의 마지막 셀에, 1-20에서 전체 열을 요약하려면, 다음의 코드 또한VBA에서 찾기 기능 사용

Sub macro2() 

Dim rng As Range 
Set rng = Range(ActiveCell, ActiveCell.End(xlDown)).Select 
rng.Find(10).Select 

End Sub 

? 응용 프로그램 개체가 그것을 수행하지 않는 것 때문에. 고맙습니다!

-
rng.End(xlDown).Offset(1, 0).Select 
Application.WorksheetFunction.Sum (rng.Value) 
+0

가짜 답변을 작성하여 귀하의 질문에 추가를 추가하지 마십시오 찾을 수의

strRw = FindColumn(Sheet name, "Value which need to be found", True, "Cell Name",Row number) sourceCOL = colname(FindColumn(Shee Name, "Value which need to be found", False, , 4)) 

아래는 주요 기능을 사용하여 편집 버튼을 사용하여 귀하의 질문에 추가 할 수 있습니다. –

+0

죄송합니다. 그냥 코멘트를 통합 – gabriel

답변

2

은 ( 에서 Select가 있지만 일반적으로 코드의 끝 부분에 위치에 사용자를 촬영 이외의 필요하지 10 처음을 선택 끝나는하는) 당신이 시도 할 수있는 활성 열에서 열을 확인합니다 발견 된 범위는
  • 당신은 또한 100 일치 피하기 위해 xlWhole를 사용해야합니다 (예 : 계속하기 전에 10을 찾을 수 있습니다) 존재
    • 시험의 경우 [바라보기위한 현재 기본 ]xlNext 등을 찾고 제 값을 구하여 [] Cells(1, ActiveCell.Column 같은 및 [검색 방향] 후 검색 를 사용 xlPart
    • 이다.

    코드

    Sub QuickFind() 
    Dim rng1 As Range 
    Set rng1 = ActiveCell.EntireColumn.Find(10, Cells(1, ActiveCell.Column), xlFormulas, xlWhole, , xlNext) 
    If Not rng1 Is Nothing Then 
    Application.Goto rng1 
    Else 
    MsgBox "10 not found" 
    End If 
    End Sub 
    

    2 부

    Sub Other() 
    Dim rng1 As Range 
    Set rng1 = Range(Cells(1, ActiveCell.Column), Cells(Rows.Count, ActiveCell.Column).End(xlUp)) 
    rng1.Cells(rng1.Cells.Count).Offset(1, 0) = Application.WorksheetFunction.Sum(rng1.Value) 
    End Sub 
    
  • +0

    브렛 감사합니다. – gabriel

    1

    하는이보십시오, 나는이 너무 특정 행 전혀뿐만 아니라 열 이름을 찾기 위해 U를 도움이되기를 바랍니다. 코드에서는,

    Public Function FindColumn(colnocountWS As Worksheet, srcstr As String, Optional rowflag As Boolean, Optional bycol As String, Optional strw As Integer, Optional stcol As Integer) As Integer 
          Dim srcrng  As Range  'range of search text 
          Dim srcAddr  As String 'address of search text 
          Dim stcolnm  As String 
    
          colnocountWS.Activate 
          If stcol <> 0 Then stcolnm = colname(stcol) 
          If stcol = 0 Then stcolnm = "A" 
          If strw = 0 Then strw = 1 
    
    
          colnocountWS.Range(stcolnm & strw).Select 
    
          If ActiveSheet.Range(stcolnm & strw) = srcstr Then 
           ActiveSheet.Range(stcolnm & strw).Select 
           FindColumn = 1 
          Else 
          If bycol = "" Then 
           Set srcrng = colnocountWS.Cells.Find(Trim(srcstr), after:=ActiveCell, LookIn:=xlValues _ 
           , LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _ 
           MatchCase:=False, SearchFormat:=False) 
          Else 
           Set srcrng = colnocountWS.Cells.Find(Trim(srcstr), after:=ActiveCell, LookIn:=xlValues _ 
           , LookAt:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _ 
           MatchCase:=False, SearchFormat:=False) 
          End If 
          'ByPart 
          If srcrng Is Nothing Then 
           If bycol = "" Then 
            Set srcrng = colnocountWS.Cells.Find(Trim(srcstr), after:=ActiveCell, LookIn:=xlValues _ 
            , LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _ 
            MatchCase:=False, SearchFormat:=False) 
           Else 
            Set srcrng = colnocountWS.Cells.Find(Trim(srcstr), after:=ActiveCell, LookIn:=xlValues _ 
            , LookAt:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _ 
            MatchCase:=False, SearchFormat:=False) 
           End If 
          End If 
    
           If srcrng Is Nothing Then 
           FindColumn = 0 
           Exit Function 
           Else 
            srcAddr = srcrng.Address 
            colnocountWS.Range(srcAddr).Select 
            FindColumn = ActiveCell.Column 
            If rowflag = True Then FindColumn = ActiveCell.Row 
           End If 
    
          End If 
         End Function 
    
         'this function find column name 
         Public Function colname(iFinalCol1 As Integer) As String 
         Dim colnm As String 
         On Error GoTo gg 
         If Mid(Cells(1, iFinalCol1).Address, 3, 1) = "$" Then 
           colnm = Mid(Cells(1, iFinalCol1).Address, 2, 1) 
          Else 
           colnm = Mid(Cells(1, iFinalCol1).Address, 2, 2) 
         End If 
         gg: colname = colnm 
    
         End Function