If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > Creating a variable range

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-30-06, 17:17
PamH PamH is offline
Registered User
 
Join Date: Jun 2006
Posts: 4
Creating a variable range

I'm trying to create a routine that will allow me to use a variable range but am not having much luck. Can anyone tell me what I might be misunderstanding here?
<<<<<<<<<<<< = differing lines....

strColLtr = ConvertColumnNumberToLetter(LastCol%)
strRangeToCopy = """" & "A1:" & strColLtr & LastRow& & """"
rngMyRng = strRangeToCopy
Sht.Range(strRangeToCopy).Select <<<<<<<<<<<<<<<<<<<<<<
Selection.Copy

when I use this, it works?
strColLtr = ConvertColumnNumberToLetter(LastCol%)
strRangeToCopy = """" & "A1:" & strColLtr & LastRow& & """"
rngMyRng = strRangeToCopy
Sht.Range("A1:G41").Select <<<<<<<<<<<<<<<<<<<<<<<<
Selection.Copy
Reply With Quote
  #2 (permalink)  
Old 07-01-06, 11:23
norie norie is offline
Registered User
 
Join Date: Mar 2006
Posts: 163
Where are you defining LastRow?

By the way you don't actually need the column letter.
Reply With Quote
  #3 (permalink)  
Old 07-03-06, 09:01
MikeTheBike MikeTheBike is offline
Registered User
 
Join Date: Apr 2004
Location: Derbyshire, UK
Posts: 714
Hi

I don't know if this helps, but you could try this, using the cells object

Code:
Sub Test()
Dim LastCol As Long
Dim LastRow As Long

LastCol = 6
LastRow = 22

ActiveSheet.Range(Cells(1, 1), Cells(LastRow, LastCol)).Select
Selection.Copy

End Sub
OR even this

Code:
Sub Test()
Dim RangeAddress As String
Dim LastCol As Long
Dim LastRow As Long

LastCol = 6
LastRow = 22

ActiveSheet.Range("A1", Cells(LastRow, LastCol)).Select
Selection.Copy

End Sub
Does that help ?


MTB
Reply With Quote
  #4 (permalink)  
Old 07-05-06, 10:55
PamH PamH is offline
Registered User
 
Join Date: Jun 2006
Posts: 4
Mike,
Thanks - this worked fine. I had defined my LastRow & LastCol elsewhere and tried converting them to a string to use. It appears that I can not use the string to pass to a range definition? I keep getting hung up on that from the record macro process....
Thanks again, Pam
Reply With Quote
  #5 (permalink)  
Old 07-05-06, 11:13
norie norie is offline
Registered User
 
Join Date: Mar 2006
Posts: 163
Pam

You can use a string to specify the range, the problem with your code could be because the string you created actually contained unneeded quotes.
Reply With Quote
  #6 (permalink)  
Old 07-05-06, 13:43
MikeroSoft MikeroSoft is offline
Registered User
 
Join Date: Apr 2006
Posts: 47
With ActiveSheet.UsedRange
MsgBox .Columns.Count
MsgBox .Rows.Count
End With
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On