LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Junior Member
 
Posts: 4
Default Range With Variables

Hi,
Here's my code:

Sub ref()

Dim RefNumber As String
Dim RefFound As Range
Dim LastRow As Long

Workbooks("2009 Hourly by res.xlsx").Sheets("Jan-Feb").Activate

With ActiveSheet
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
End With

RefNumber = Application.InputBox("Reference #", "Meter Point Reference Number")

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

Range(Cells(5, RefFound), Cells(LastRow, RefFound)).Select

MsgBox "Found Ref # at column" & RefFound.Column
MsgBox "and last row at" & LastRow
End Sub
----------------------------------------
When i run this code I get a runtime error 1004 (only happens with my range line in)

LastRow will be the final row and RefFound.Column is the column for my range.

If anyone could help with this I'm having a hard time creating a select range with my variables.

Thanks,
Chris
 
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
Range variables carl Excel Programming 1 October 25th 07 12:10 PM
VBA Range Variables... MarkHear1 Excel Programming 2 February 15th 07 11:53 AM
Set few range variables at once Greg Excel Programming 4 November 15th 06 01:01 AM
Range of variables Ed Excel Programming 2 August 5th 06 03:05 PM
Range Variables Daniel[_7_] Excel Programming 1 November 20th 03 05:45 AM


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