Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Dynamic Range


The code below works fine but my range to copy is dynamic,
so that in the below ("K3:R3") could be ("M3:S3")
I have defined my first and last columns by firstcol and lastcol
respectively.
so that instead of ("K3:R3") I want something lik
Range("(firstcol)3:(firstcol)3")

Many Thanks



Sheets("NATWEST").Select
Range("K3:R3").Copy
Sheets("MTS TOTAL").Select
Range("C12").Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone
SkipBlanks:= _
False, Transpose:=Tru

--
T De Villier
-----------------------------------------------------------------------
T De Villiers's Profile: http://www.excelforum.com/member.php...fo&userid=2647
View this thread: http://www.excelforum.com/showthread.php?threadid=56701

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,646
Default Dynamic Range

If firstcol and lastcol are strings containing column letters, then
Range(firstcol & "3:" & lastcol & "3")
If they are column numbers, first convert them to letters with this function:
Function GetColLet(ColNumber As Integer) As String
GetColLet = Left(Cells(1, ColNumber).Address(False, False), 1 -
(ColNumber 26))
End Function

firstclet=GetColLet(firstcol)
lastclet=GetColLet(lastcol)
Range(firstclet & "3:" & lastclet & "3")

Regards,
Stefi

€˛T De Villiers€¯ ezt Ć*rta:


The code below works fine but my range to copy is dynamic,
so that in the below ("K3:R3") could be ("M3:S3")
I have defined my first and last columns by firstcol and lastcol
respectively.
so that instead of ("K3:R3") I want something like
Range("(firstcol)3:(firstcol)3")

Many Thanks



Sheets("NATWEST").Select
Range("K3:R3").Copy
Sheets("MTS TOTAL").Select
Range("C12").Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone,
SkipBlanks:= _
False, Transpose:=True


--
T De Villiers
------------------------------------------------------------------------
T De Villiers's Profile: http://www.excelforum.com/member.php...o&userid=26479
View this thread: http://www.excelforum.com/showthread...hreadid=567018


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 380
Default Dynamic Range

Sheets("NATWEST").Select
Range(Cells(3,firstcol),Cells(3,lastCol)).Copy
Sheets("MTS TOTAL").Select
Range("C12").Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone,
SkipBlanks:= _
False, Transpose:=True

--

HTH

Bob Phillips

(replace xxxx in the email address with gmail if mailing direct)

"T De Villiers"
wrote in message
news:T.De.Villiers.2bv4rf_1154438407.9249@excelfor um-nospam.com...

The code below works fine but my range to copy is dynamic,
so that in the below ("K3:R3") could be ("M3:S3")
I have defined my first and last columns by firstcol and lastcol
respectively.
so that instead of ("K3:R3") I want something like
Range("(firstcol)3:(firstcol)3")

Many Thanks



Sheets("NATWEST").Select
Range("K3:R3").Copy
Sheets("MTS TOTAL").Select
Range("C12").Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone,
SkipBlanks:= _
False, Transpose:=True


--
T De Villiers
------------------------------------------------------------------------
T De Villiers's Profile:

http://www.excelforum.com/member.php...o&userid=26479
View this thread: http://www.excelforum.com/showthread...hreadid=567018



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Dynamic Range

Similar to what has been suggested in the past:

Range(cells(3,firstcol),cells(lastcol,3)).Copy


or for a specific sheet (not the activesheet)

with worksheets("NATWEST")
.Range(.cells(3,firstcol),.cells(lastcol,3)).Copy
End With
Worksheets("MTS TOTAL").Range("C12").PasteSpecial _
Paste:=xlPasteAll, _
Operation:=xlNone, _
SkipBlanks:=False, _
Transpose:=True

--
Regards,
Tom Ogilvy


"T De Villiers" wrote:


The code below works fine but my range to copy is dynamic,
so that in the below ("K3:R3") could be ("M3:S3")
I have defined my first and last columns by firstcol and lastcol
respectively.
so that instead of ("K3:R3") I want something like
Range("(firstcol)3:(firstcol)3")

Many Thanks



Sheets("NATWEST").Select
Range("K3:R3").Copy
Sheets("MTS TOTAL").Select
Range("C12").Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone,
SkipBlanks:= _
False, Transpose:=True


--
T De Villiers
------------------------------------------------------------------------
T De Villiers's Profile: http://www.excelforum.com/member.php...o&userid=26479
View this thread: http://www.excelforum.com/showthread...hreadid=567018


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
getting the absolute range address from a dynamic named range junoon Excel Programming 2 March 21st 06 01:29 PM
Dynamic Range with unused formula messing up x axis on dynamic graph [email protected] Charts and Charting in Excel 2 February 2nd 06 08:02 PM
copying dynamic range based on cell outside of range xcelelder Excel Programming 3 September 29th 05 05:08 PM
select dynamic range with dynamic start point Juli Excel Programming 1 August 31st 05 12:05 AM
Excel 2000 VBA - Set Print Range in dynamic range sub_pop[_5_] Excel Programming 2 July 27th 04 08:01 PM


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