Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
ppbedz
 
Posts: n/a
Default Help - retrieve cell address


I would like to retrieve the address of a cell that contains a specific
text value ie. "Grand Total". I then want to substitue the row number
portion of the address into a macro so that I can copy everything in my
spreadsheet PRIOR to the "Grand Total" row. I am just getting into
macros and more complicated spreadsheet processing so I could really
use some help.

Thank you


--
ppbedz
------------------------------------------------------------------------
ppbedz's Profile: http://www.excelforum.com/member.php...o&userid=33559
View this thread: http://www.excelforum.com/showthread...hreadid=533456

  #2   Report Post  
Posted to microsoft.public.excel.misc
Toppers
 
Posts: n/a
Default Help - retrieve cell address

One way:

Sub a()


With Worksheets(1).Range("a1:D500") ' <=== change to suit
Set c = .Find("Grand Total", LookIn:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
Do
MsgBox c.Address
MsgBox c.Row
MsgBox c.Column
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address < firstAddress
End If
End With

End Sub


HTH
"ppbedz" wrote:


I would like to retrieve the address of a cell that contains a specific
text value ie. "Grand Total". I then want to substitue the row number
portion of the address into a macro so that I can copy everything in my
spreadsheet PRIOR to the "Grand Total" row. I am just getting into
macros and more complicated spreadsheet processing so I could really
use some help.

Thank you


--
ppbedz
------------------------------------------------------------------------
ppbedz's Profile: http://www.excelforum.com/member.php...o&userid=33559
View this thread: http://www.excelforum.com/showthread...hreadid=533456


  #3   Report Post  
Posted to microsoft.public.excel.misc
Gary''s Student
 
Posts: n/a
Default Help - retrieve cell address

This finds the first occurance of a cell containing Grand Total and outputs
the row number of that cell:


Sub Macro1()
Dim r As Range
For Each r In Selection
If r.Value = "Grand Total" Then
Exit For
End If
Next
MsgBox (r.Row)
End Sub

--
Gary''s Student


"ppbedz" wrote:


I would like to retrieve the address of a cell that contains a specific
text value ie. "Grand Total". I then want to substitue the row number
portion of the address into a macro so that I can copy everything in my
spreadsheet PRIOR to the "Grand Total" row. I am just getting into
macros and more complicated spreadsheet processing so I could really
use some help.

Thank you


--
ppbedz
------------------------------------------------------------------------
ppbedz's Profile: http://www.excelforum.com/member.php...o&userid=33559
View this thread: http://www.excelforum.com/showthread...hreadid=533456


  #4   Report Post  
Posted to microsoft.public.excel.misc
ppbedz
 
Posts: n/a
Default Help - retrieve cell address


Thank you.

Next question....

How do I substitute r.Value into my range statement below? I
essentially want to say from A5 through r.Value


Range("A5:J65000").Select


Thanks Again! :)


--
ppbedz
------------------------------------------------------------------------
ppbedz's Profile: http://www.excelforum.com/member.php...o&userid=33559
View this thread: http://www.excelforum.com/showthread...hreadid=533456

  #5   Report Post  
Posted to microsoft.public.excel.misc
ppbedz
 
Posts: n/a
Default Help - retrieve cell address


Thank you.

Next question....

How do I substitute r.Value into my range statement below? I
essentially want to say from A5 through r.Value


Range("A5:J65000").Select


Thanks Again! :)


--
ppbedz
------------------------------------------------------------------------
ppbedz's Profile: http://www.excelforum.com/member.php...o&userid=33559
View this thread: http://www.excelforum.com/showthread...hreadid=533456



  #6   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson
 
Posts: n/a
Default Help - retrieve cell address

If you record a macro when you do Edit|Find, you can search the range (a single
column or the whole sheet) for that phrase. Then if it's found, you can use
that cell to get the row number (and row number - 1).

Option Explicit
Sub testme02()

Dim FoundCell As Range
Dim wks As Worksheet
Dim RngToCopy As Range
Dim DestCell As Range

Set wks = Worksheets("sheet1")

With Worksheets("Sheet2")
Set DestCell = .Range("a1")
End With

With wks
With .Range("A:A") '.usedrange '????
Set FoundCell = .Cells.Find(What:="grand total", _
After:=.Cells(.Cells.Count), LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False)
End With

If FoundCell Is Nothing Then
'do nothing
Else
If FoundCell.Row 1 Then
Set RngToCopy = .Rows("1:" & FoundCell.Row - 1)
RngToCopy.Copy _
Destination:=DestCell
End If
End If
End With

End Sub

I only looked in column A, but you could look in any range.


ppbedz wrote:

I would like to retrieve the address of a cell that contains a specific
text value ie. "Grand Total". I then want to substitue the row number
portion of the address into a macro so that I can copy everything in my
spreadsheet PRIOR to the "Grand Total" row. I am just getting into
macros and more complicated spreadsheet processing so I could really
use some help.

Thank you

--
ppbedz
------------------------------------------------------------------------
ppbedz's Profile: http://www.excelforum.com/member.php...o&userid=33559
View this thread: http://www.excelforum.com/showthread...hreadid=533456


--

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
Find max number of character and return cell address ExcelMonkey Excel Worksheet Functions 5 April 15th 06 04:13 AM
Address of Maximum value in Cell Session101 Excel Worksheet Functions 1 April 12th 06 09:06 PM
Insert Cell Contents in middle of web address Jetheat Excel Discussion (Misc queries) 2 March 5th 06 07:18 PM
Cell Address Matching khalid Excel Worksheet Functions 1 December 27th 05 02:17 PM
Can the column index in a cell address be made variable? cyberdude Excel Discussion (Misc queries) 1 November 20th 05 02:47 AM


All times are GMT +1. The time now is 04:25 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"