ID Column Number

bobkap

Active Member
Joined
Nov 22, 2009
Messages
323
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
  3. Web
In the code below, I'm trying to find the NUMBER of the column where "coursecol" is located. Presently, my formula returns a text string such as "BLS Class". But, so I can use coursecol in a Vlookup which would identify the column number, I need the number of the cell location as we use when we do something like Cells(4,18). I want to know what the 18, in this case, is for my text string. Any help would be greatly appreciated.

counter2 = 1
finalrow2 = (Sheets("Payrates").Cells(Rows.Count, finalcol3).End(xlUp).Row)
For counter2 = counter2 To finalrow2
If (Worksheets("Payrates").Cells(inputrow5, inputcol5).Value = coursename) Then
coursecol = (Worksheets("Payrates").Cells(inputrow5, inputcol5).Value)
Exit For
End If
inputcol5 = inputcol5 + 1
Next counter2
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Assuming the coursename variable got its value earlier, I would think this single line of code should work...
Code:
[table="width: 500"]
[tr]
	[td]coursecol = Cells.Find(coursename, , xlValues, xlWhole, , , False, , False).Column[/td]
[/tr]
[/table]
 
Upvote 0
Thanks very much, but I get this error message with that code: Run-time error '91': Object variable or With block variable not set. I assume this means I'm missing a 'set' statement? But, I don't quite understand how or where to do so.
 
Upvote 0
Thanks very much, but I get this error message with that code: Run-time error '91': Object variable or With block variable not set. I assume this means I'm missing a 'set' statement? But, I don't quite understand how or where to do so.
Sorry, I forgot about your worksheet name. By the way, that error message means the text you searched for was not on the sheet being searched which, unfortunately, was the active worksheet and not the sheet named Payrates. Try this instead...
Code:
[table="width: 500"]
[tr]
	[td]coursecol = Worksheets("Payrates").Cells.Find(coursename, , xlValues, xlWhole, , , False, , False).Column[/td]
[/tr]
[/table]
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top