2016-04-17 5 views
-2

列番号が動的な場合にコードを動作させる方法は?VBA - 列番号が動的なときにコードを動作させる方法

いくつかの時間がcol Bで作業する必要があり、いくつかの時間がcol C(タイトルは同じである)のときにコードを動作させたいですか?

ありがとうございました。

+1

"the code" ??コードを見せてください! –

+0

おそらく変数を使用していますか? –

答えて

0

使用変数は..私は私の列を取得するには、次の機能を使用します。

'----------------------------------------------------------------- 
' Purpose   Retrieves the column number - searches in a 
'     listobject header 
' Requires   string to search 
'     range (listobject name) 
' Important   needs range with [#headers], eg 
'     Range("Customers[#Headers]") 
' Example   To find out in which column number 'Phone' in 
'     table 'Customers' is located, you use 
'     GetColumn("Phone",Range("Customers[#Headers]") 
'----------------------------------------------------------------- 
Function GetColumn(str As String, rng As Range) As Integer 
GetColumn = Application.WorksheetFunction.Match(str, rng, 0) 
End Function 
0

おかげで、どのように私はサブでそれを使用することができますか()?

Public Function GetColumn(str As String, rng As Range) As Integer 
GetColumn = Application.Sheets("Sheet1").Match("Supplier", "POC[#Headers]", 0) 

End Function 
Sub i() 






NumRows = cells(Rows.Count, "e").End(xlUp).Row 
    For i = 2 To NumRows 

    Supplier = cells(i, 16).Value 

    Select Case Supplier 
     Case "EDLC", "ANC", "EdTD", "ENC", "APASA P", "EBANROPE", "EVANC" 

     GetColumn.Value = "Zaya" 


    End Select 

    Next i 

    End Sub 
関連する問題