I'm struggling with how to use the Find method.

I'm trying to automate a rather complex analysis of 10 or 15 columns of data. My code needs to be able to deal with the fact that the data will often be in different columns depending on the user, but so far nothing I've tried works and it all looks clunky to boot.

Would anyone be able to suggest how I could do something like

Dim voltageColumn as integer

Range("A3:Z3") .Find("Sensor voltage").Select

voltageColumn = ActiveCell.Column

. Thanks in advance for any help.

Re: HdI use Find to set a variable = column #?


Here is the one you are looking for

Dim rFnd
voltageColumn = 0
Set rFnd = ActiveSheet.Range("A3:Z3").Find(what:="Sensor voltage", LookIn:=xlValues, lookat:=xlPart)
If Not rFnd Is Nothing Then
voltageColumn = rFnd .Column
End If

The advantage here is you are assigning value to voltageColumn, only if you find the required text

Re: HdI use Find to set a variable = column #?


Shasur, that works PERFECTLY! Thanks a whole bunch.