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


I am new to vba in Excel and have written a macro that works well but
keeps falling over.

The code is as follows:

Dim costcentre As Range
Dim LastSht As Long
Sheets("Header").Select
LastSht = Sheets.Count
Set costcentre = Range("e4")
Sheets("Template").Select
Sheets("Template").Copy after:=Sheets(LastSht)
Sheets("Template (2)").Select
Range("av7").Value = costcentre
Range("Q17:ab17").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone,
SkipBlanks:= _
False, Transpose:=False
Range("q21:ab43").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone,
SkipBlanks:= _
False, Transpose:=False
Sheets("Template (2)").Name = costcentre
Columns("A:O").Hidden = True
Columns("Ai:dd").Hidden = True
'Sheets("Header").Select
'Range("costcentre").Select

It is this last line that falls over. It is ok if I use a specifc
reference eg "e4" but I don't want to do this as I want to offset one
cell down each time through when I add a loop. Can I not use the
declared name to go to a cell?

Any halp much appreciated.

Thanks

Andrew


--
AndrewCrisp
------------------------------------------------------------------------
AndrewCrisp's Profile: http://www.excelforum.com/member.php...o&userid=36653
View this thread: http://www.excelforum.com/showthread...hreadid=564035

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,073
Default VBA Range Property


Hi Andrew,

Excel is looking for a named range named "costcentre" and probably
can't find such a named range.

Your code has set the variable "costcentre" to represent the range E4,
so I think your last line should be...

costcentre.select

Ken Johnson

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA Range Property


Ken

Simple but did the trick.

Many thanks

Andrew


--
AndrewCrisp
------------------------------------------------------------------------
AndrewCrisp's Profile: http://www.excelforum.com/member.php...o&userid=36653
View this thread: http://www.excelforum.com/showthread...hreadid=564035

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,073
Default VBA Range Property


You're welcome Andrew.
Thanks for the feedback.

Ken Johnson

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
range property of range object Woody[_3_] Excel Programming 1 June 23rd 05 09:04 PM
Row and Column from Used Range property?? C. Johnson Excel Programming 1 March 31st 05 07:51 PM
Weird range property behaviour Gareth Thackeray Excel Programming 5 November 2nd 04 01:15 PM
Range Resize property jacqui[_2_] Excel Programming 7 February 24th 04 06:11 PM
using a range with isnumber property chick-racer[_33_] Excel Programming 2 November 12th 03 06:53 PM


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