Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default relative versus specific cells in macros/vba

A macro I'm trying to write has to include a "copy-find-paste-modify" string,
but I don't know how to generalize the active cell choice to be dependant
upon the results of the "find" rather than a specific cell typed in vba.

So, how do I write "find cell, move four cells to the right of found cell,
modify that cell" rather than, "move to r1c1, modify?" I'm looking
essentially for a variable plug within r1c1 rather than a specific grid
placement.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 644
Default relative versus specific cells in macros/vba

Dim fCell as Range
Set fCell = Cells.Find(What:=SearchText, After:=StartCell,
LookIn:=xlFormulas, _
LookAt:=xlWhole, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=True).Offset(0,4)
fCell = "Hello From Iowa"

HTH

Die_Another_Day
Stutsman wrote:
A macro I'm trying to write has to include a "copy-find-paste-modify" string,
but I don't know how to generalize the active cell choice to be dependant
upon the results of the "find" rather than a specific cell typed in vba.

So, how do I write "find cell, move four cells to the right of found cell,
modify that cell" rather than, "move to r1c1, modify?" I'm looking
essentially for a variable plug within r1c1 rather than a specific grid
placement.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default relative versus specific cells in macros/vba

One slight modification that makes things a bit more robust:

Dim fCell As Range
Set fCell = Cells.Find(What:=SearchText, _
After:=StartCell, _
LookAt:=xlWhole, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=True)
If fCell Is Nothing Then
Msgbox SearchText & " was not found."
Else
With fCell.Offset(0, 4)
.Value = .Value & " modified"
End With
End If



In article .com,
"Die_Another_Day" wrote:

Dim fCell as Range
Set fCell = Cells.Find(What:=SearchText, After:=StartCell,
LookIn:=xlFormulas, _
LookAt:=xlWhole, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=True).Offset(0,4)
fCell = "Hello From Iowa"

HTH

Die_Another_Day
Stutsman wrote:
A macro I'm trying to write has to include a "copy-find-paste-modify"
string,
but I don't know how to generalize the active cell choice to be dependant
upon the results of the "find" rather than a specific cell typed in vba.

So, how do I write "find cell, move four cells to the right of found cell,
modify that cell" rather than, "move to r1c1, modify?" I'm looking
essentially for a variable plug within r1c1 rather than a specific grid
placement.

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
multiple distances versus lowest time for a specific distance shell aw New Users to Excel 1 October 4th 09 03:41 AM
How do I write macros with relative reference cells trilogylynch Excel Programming 3 July 25th 05 09:15 PM
Macros - Relative cells in Excel BeardT Excel Programming 4 October 14th 04 09:55 PM
Create macros to print specific cells Richy Excel Programming 3 February 17th 04 03:42 PM
Macros i XL 2003 versus 2000 - speed problems Ankan[_2_] Excel Programming 2 December 10th 03 12:08 PM


All times are GMT +1. The time now is 04:37 PM.

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

About Us

"It's about Microsoft Excel"