Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 69
Default Getting and Saving a Cell Reference

I am searching in a table for a specific heading, for example ABS. Now as I
am receiving this information from a 3rd party, that ABS could be in column
10 on one file, but in column 54 in the next. I would like to retreive the
column number of that heading, store it within the macro to use for sorting
and other funtions I am creating. How can I get just the column, or just the
row, or both if I need it. The address function is what I would use in Excel.

Thanks.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,942
Default Getting and Saving a Cell Reference

hi,
try working something like this into your macro..
Sub arc()
Dim a As String
Dim b As String
Dim c As Long
Dim d As Long
a = InputBox("enter something")
Cells.Find(What:="a", After:=ActiveCell, _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False).Activate
b = ActiveCell.Address
c = ActiveCell.Row
d = ActiveCell.Column
MsgBox b
MsgBox c
MsgBox d

End Sub
the code is wordy but only to show your the 3 items you mentioned. row,
column and/or address.

regards
FSt1
"Marco" wrote:

I am searching in a table for a specific heading, for example ABS. Now as I
am receiving this information from a 3rd party, that ABS could be in column
10 on one file, but in column 54 in the next. I would like to retreive the
column number of that heading, store it within the macro to use for sorting
and other funtions I am creating. How can I get just the column, or just the
row, or both if I need it. The address function is what I would use in Excel.

Thanks.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Getting and Saving a Cell Reference

You could use the same thing as Edit|Find in code:


Dim FoundCell as range
Dim WhatToFind as String

whattofind = "ABS"

With someworksheetvariablehere

Set FoundCell = .Cells.Find(What:=whattofind, _
after:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
lookat:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)

end with

if foundcell is nothing then
msgbox "not found
else
msgbox foundcell.address & vblf & foundcell.row & vblf & foundcell.column
end if

If you know it's in row 1, you could be more specific:

With someworksheetvariablehere
with .rows(1)
Set FoundCell = .Cells.Find(What:=whattofind, _
after:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
lookat:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
end with
end with
.....



Marco wrote:

I am searching in a table for a specific heading, for example ABS. Now as I
am receiving this information from a 3rd party, that ABS could be in column
10 on one file, but in column 54 in the next. I would like to retreive the
column number of that heading, store it within the macro to use for sorting
and other funtions I am creating. How can I get just the column, or just the
row, or both if I need it. The address function is what I would use in Excel.

Thanks.


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 69
Default Getting and Saving a Cell Reference

This should do it. Thanks for taking the extra time to show me what the code
will do.

Cheers.

"FSt1" wrote:

hi,
try working something like this into your macro..
Sub arc()
Dim a As String
Dim b As String
Dim c As Long
Dim d As Long
a = InputBox("enter something")
Cells.Find(What:="a", After:=ActiveCell, _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False).Activate
b = ActiveCell.Address
c = ActiveCell.Row
d = ActiveCell.Column
MsgBox b
MsgBox c
MsgBox d

End Sub
the code is wordy but only to show your the 3 items you mentioned. row,
column and/or address.

regards
FSt1
"Marco" wrote:

I am searching in a table for a specific heading, for example ABS. Now as I
am receiving this information from a 3rd party, that ABS could be in column
10 on one file, but in column 54 in the next. I would like to retreive the
column number of that heading, store it within the macro to use for sorting
and other funtions I am creating. How can I get just the column, or just the
row, or both if I need it. The address function is what I would use in Excel.

Thanks.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 69
Default Getting and Saving a Cell Reference

Thank you for your help.

I found the reply from FTs1 a bit easier to follow and will probably go with
that one.

Cheers.

"Dave Peterson" wrote:

You could use the same thing as Edit|Find in code:


Dim FoundCell as range
Dim WhatToFind as String

whattofind = "ABS"

With someworksheetvariablehere

Set FoundCell = .Cells.Find(What:=whattofind, _
after:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
lookat:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)

end with

if foundcell is nothing then
msgbox "not found
else
msgbox foundcell.address & vblf & foundcell.row & vblf & foundcell.column
end if

If you know it's in row 1, you could be more specific:

With someworksheetvariablehere
with .rows(1)
Set FoundCell = .Cells.Find(What:=whattofind, _
after:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
lookat:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
end with
end with
.....



Marco wrote:

I am searching in a table for a specific heading, for example ABS. Now as I
am receiving this information from a 3rd party, that ABS could be in column
10 on one file, but in column 54 in the next. I would like to retreive the
column number of that heading, store it within the macro to use for sorting
and other funtions I am creating. How can I get just the column, or just the
row, or both if I need it. The address function is what I would use in Excel.

Thanks.


--

Dave Peterson

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
invalid reference error saving 2003 file in 2007 Gary C Excel Discussion (Misc queries) 0 December 8th 09 02:58 PM
Saving data from a cell reference [email protected] Excel Discussion (Misc queries) 0 July 10th 08 03:33 AM
How do I save Excel info without saving the reference cells? Dave Excel Discussion (Misc queries) 2 July 9th 06 09:38 PM
problem with cell reference in =sum(offset(cell reference,x,y,z,a)). Want cell ref to be variable. [email protected] Excel Worksheet Functions 2 December 11th 04 12:05 AM
Problem with =sum(offset(cell reference,w,x,y,z). I want cell reference to be variable [email protected] Excel Worksheet Functions 2 December 11th 04 12:00 AM


All times are GMT +1. The time now is 12:54 PM.

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"