Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default Finding column again

I posted a message before asking how to find the column within a range which
held a six digit number. Tom Ogilvy kindly provided some codes as below
Dim ans as String, num as Long
Dim res as Variant
ans = Inputbox("Enter 6 digit number")
if isnumeric(ans) and len(trim(ans)) = 6 then
num = clng(ans)
res = application.Match(num, range("A1:E1"),0)
if not iserror(res) then
col = range("A1")(1, res).Column
else
msgbox "Not found"
end if
End if

This gives me the column number. But I would like the corresponding letter
of the column. For example If the sis dogit number was in column G, I would
like to update 3 cells in column G (e.g. range("G5").select ActiveCell =
"Done" Range("G7").Select ActiveCell = "OK" and so on) If column was H then
I would update H5, H7 and so on. How can I do this in VB?

Thank you
Prema
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Finding column again

using the letter instead of the column Number would be the backwards way to
do it.

Dim ans as String, num as Long
Dim res as Variant
ans = Inputbox("Enter 6 digit number")
if isnumeric(ans) and len(trim(ans)) = 6 then
num = clng(ans)
res = application.Match(num, range("A1:E1"),0)
if not iserror(res) then
col = range("A1")(1, res).Column
cells(5,col).Value = "Done"
cells(7,col).Value = "OK"
cells(9,col).Value = "And So On"
else
msgbox "Not found"
end if
End if


If you absolutely need the column letter - using col from the existing code

Dim sStr as String
sStr = Left(cells(1,col).Address(0,0), 2 + (col <= 26))
msgbox "Column letter: " & sStr


--
Regards,
Tom Ogilvy



"Prema" wrote in message
...
I posted a message before asking how to find the column within a range

which
held a six digit number. Tom Ogilvy kindly provided some codes as below
Dim ans as String, num as Long
Dim res as Variant
ans = Inputbox("Enter 6 digit number")
if isnumeric(ans) and len(trim(ans)) = 6 then
num = clng(ans)
res = application.Match(num, range("A1:E1"),0)
if not iserror(res) then
col = range("A1")(1, res).Column
else
msgbox "Not found"
end if
End if

This gives me the column number. But I would like the corresponding letter
of the column. For example If the sis dogit number was in column G, I

would
like to update 3 cells in column G (e.g. range("G5").select ActiveCell =
"Done" Range("G7").Select ActiveCell = "OK" and so on) If column was H

then
I would update H5, H7 and so on. How can I do this in VB?

Thank you
Prema



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Finding column again

Prema,

There is no reason to use the column letter once you have the column
number - simply use the Cells(row #, col#) property of the sheet rather than
the Range property. So cell H6 is Cells(6,8)

HTH,
Bernie
MS Excel MVP

"Prema" wrote in message
...
I posted a message before asking how to find the column within a range

which
held a six digit number. Tom Ogilvy kindly provided some codes as below
Dim ans as String, num as Long
Dim res as Variant
ans = Inputbox("Enter 6 digit number")
if isnumeric(ans) and len(trim(ans)) = 6 then
num = clng(ans)
res = application.Match(num, range("A1:E1"),0)
if not iserror(res) then
col = range("A1")(1, res).Column
else
msgbox "Not found"
end if
End if

This gives me the column number. But I would like the corresponding letter
of the column. For example If the sis dogit number was in column G, I

would
like to update 3 cells in column G (e.g. range("G5").select ActiveCell =
"Done" Range("G7").Select ActiveCell = "OK" and so on) If column was H

then
I would update H5, H7 and so on. How can I do this in VB?

Thank you
Prema



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default Finding column again

Thank you very much Tom. I was thinking only in one way. Of course what you
have said is best.
Prema

"Prema" wrote:

I posted a message before asking how to find the column within a range which
held a six digit number. Tom Ogilvy kindly provided some codes as below
Dim ans as String, num as Long
Dim res as Variant
ans = Inputbox("Enter 6 digit number")
if isnumeric(ans) and len(trim(ans)) = 6 then
num = clng(ans)
res = application.Match(num, range("A1:E1"),0)
if not iserror(res) then
col = range("A1")(1, res).Column
else
msgbox "Not found"
end if
End if

This gives me the column number. But I would like the corresponding letter
of the column. For example If the sis dogit number was in column G, I would
like to update 3 cells in column G (e.g. range("G5").select ActiveCell =
"Done" Range("G7").Select ActiveCell = "OK" and so on) If column was H then
I would update H5, H7 and so on. How can I do this in VB?

Thank you
Prema

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
finding the largest value for a name in a column and then returningthe result from a different column [email protected] Excel Worksheet Functions 1 April 14th 08 10:08 AM
Finding Info from Column A and Removing it from Column B Johnny B[_2_] Excel Discussion (Misc queries) 2 March 28th 07 12:06 PM
Finding the closest number in column A and take the value in column B reefguy Excel Worksheet Functions 3 May 5th 06 07:25 PM
Output from a userform finding the right column. column HelpMe Excel Programming 1 February 10th 04 03:27 PM
finding and reporting in column A, where a series of column reaches zero Gary Tamblyn Excel Programming 2 July 27th 03 12:00 PM


All times are GMT +1. The time now is 03:42 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"