Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() 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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() 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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() 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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() You're welcome Andrew. Thanks for the feedback. Ken Johnson |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
range property of range object | Excel Programming | |||
Row and Column from Used Range property?? | Excel Programming | |||
Weird range property behaviour | Excel Programming | |||
Range Resize property | Excel Programming | |||
using a range with isnumber property | Excel Programming |