Home > Software engineering >  Ask how VBA loop according to the number of columns to find a match?
Ask how VBA loop according to the number of columns to find a match?

Time:12-22

ActiveSheet. UsedRange. Columns. The Count is the number of Columns of

The purpose is to:

From the first column to column N (that is, the total number of columns) check mei column first line is the A1 B1 C1...

If you have and want to find the target such as if the first column is data type to find "file name" so if a column in the first paragraph of the text is "file name" is returned the column of

Excuse me, does this how to write in circulation? Before the cycle is according to the lines of the number of columns to do? Thank you very much!

CodePudding user response:

For example, please refer to:
 Option Explicit 
Sub test ()
The Debug. Print FindCol (" w2 ")
The Debug. Print FindCols; "W2"
End Sub
The Function FindCol (ByVal bText As String) As an Integer
"' using vba function
Dim Rng As Range
The Set Rng=Sheet1. Rows (" 1 "). The Find (credit:=bText, LookIn:=xlValues, LookAt:=xlWhole)
If Not Rng Is Nothing Then FindCol=Rng. Column
The Set of Rng=Nothing
End the Function
The Function FindCols (ByVal bText As String) As an Integer
"' cycle
Dim As Integer I
With Sheet1
For I=1 To.. Cells. Columns. The Count
If StrComp (bText, Cells (1, I). The Text, vbTextCompare)=0 Then
FindCols=I
The Exit For
End the If
Next
End With
End the Function


.
  •  Tags:  
  • VBA
  • Related