ActiveSheet.UsedRange.Columns.Count算的列數
目的是:
從第一列到第N列(也就是總列數) 檢查梅列第一行 也就是A1 B1 C1...
如果有和要查找目標值 比如如果第一列是資料類項的話 要找“檔案名” 那么如果某一列第一項的text是“檔案名”就回傳這一列
請問這該怎么用回圈寫?之前回圈都是根據行數 這次列數怎么做?謝謝啊
uj5u.com熱心網友回復:
舉例,請參考:Option Explicit
Sub test()
Debug.Print FindCol("w2")
Debug.Print FindCols; "W2"
End Sub
Function FindCol(ByVal bText As String) As Integer
''使用vba函式
Dim Rng As Range
Set Rng = Sheet1.Rows("1:1").Find(What:=bText, LookIn:=xlValues, LookAt:=xlWhole)
If Not Rng Is Nothing Then FindCol = Rng.Column
Set Rng = Nothing
End Function
Function FindCols(ByVal bText As String) As Integer
''回圈
Dim i As Integer
With Sheet1
For i = 1 To .Cells.Columns.Count
If StrComp(bText, .Cells(1, i).Text, vbTextCompare) = 0 Then
FindCols = i
Exit For
End If
Next
End With
End Function
.
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/76758.html
標籤:VBA
