Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default VBA: Attach a variable to a range after executing Find command

If I execute a find command, is there a way to select a range based on what
is found and store it as a variable? I have done the following:

Cells.Find(What:=Month_Year, After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate

Selection.End(xlDown).Select

Cells(ActiveCell.Row + 1, ActiveCell.Column).Value = "Allocated Month"
Cells(ActiveCell.Row + 1, ActiveCell.Column + 1).Value = "Location
Assigned"
Cells(ActiveCell.Row + 1, ActiveCell.Column + 2).Value = "Assigned Person"
Cells(ActiveCell.Row + 2, ActiveCell.Column).Value = Month_Year
Cells(ActiveCell.Row + 2, ActiveCell.Column + 1).Value = Location
Cells(ActiveCell.Row + 2, ActiveCell.Column + 2).Value = Name

I now want to be able to select everything that was just entered and store
it as a range that can be used in a DSUM formula later on. Any suggestions?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default VBA: Attach a variable to a range after executing Find command

If you declare c (Dim c As Range) and use:

Set c = Cells.Find(What:=Month_Year, After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)

Then you can do:

If not c Is Nothing
myVar = c.Value
myAdr = c.Address
End If

Which stores the found cell value in myVar and
store the cell address in myAdr. Then

Range(myAdr) = myVar

Would be true.

"Jayne22" wrote:

If I execute a find command, is there a way to select a range based on what
is found and store it as a variable? I have done the following:

Cells.Find(What:=Month_Year, After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate

Selection.End(xlDown).Select

Cells(ActiveCell.Row + 1, ActiveCell.Column).Value = "Allocated Month"
Cells(ActiveCell.Row + 1, ActiveCell.Column + 1).Value = "Location
Assigned"
Cells(ActiveCell.Row + 1, ActiveCell.Column + 2).Value = "Assigned Person"
Cells(ActiveCell.Row + 2, ActiveCell.Column).Value = Month_Year
Cells(ActiveCell.Row + 2, ActiveCell.Column + 1).Value = Location
Cells(ActiveCell.Row + 2, ActiveCell.Column + 2).Value = Name

I now want to be able to select everything that was just entered and store
it as a range that can be used in a DSUM formula later on. Any suggestions?

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
vba: attach a variable name to a selected range Jayne22 Excel Programming 4 August 7th 08 10:54 PM
Executing dos command Furqi Excel Programming 2 May 29th 08 09:57 AM
Executing a command when clicking on a tab Bob Excel Programming 6 August 28th 07 01:00 AM
Need help using a variable in Range command cbeebe[_7_] Excel Programming 1 November 5th 04 05:29 PM
Variable usage in Range Command DavidC[_2_] Excel Programming 2 May 27th 04 03:51 AM


All times are GMT +1. The time now is 05:41 AM.

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"