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

Hi Guys,

I was trying to understand how to use the Range.Resize property but
after much googling and reading of help files gave up on that and tried
another tack.

That was to create a completely new range by using Range( cells( row,
column), cells( row, column)).

The following sub works as I would expect it to, but one thing I don't
understand, which highlights my ignorance of what I am actually doing,
is this. In the following code there are two commented MsgBoxes, the
first MsgBox produces an expected address, the second MsgBox produces a
different result I would assume because of the shift of cells.

Why does the shift of cells cause the address of my variable to change
though?

Thanks in advance,
Deon.

Sub testresize()

Dim testRange As Range
Dim newRange As Range
Dim addRows As Integer
Dim rngStartColumn As Integer
Dim rngStartRow As Integer
Dim rngEndColumn As Integer
Dim rngEndRow As Integer

addRows = 6
rngStartColumn = 0
rngStartRow = 0
rngEndColumn = 0
rngEndRow = 0

Set testRange = Range("B6:D6")
Set newRange = Range("B6:D6")

rngStartColumn = testRange.Column
rngEndColumn = rngStartColumn + testRange.Columns.Count - 1
rngStartRow = testRange.Row
rngEndRow = rngStartRow + testRange.Rows.Count - 1

With ActiveSheet
Set newRange = .Range(.Cells(rngStartRow, rngStartColumn),
..Cells(rngEndRow + addRows, rngEndColumn))

'' This MsgBox produces the expected result
MsgBox "Address before shift " & newRange.Address
newRange.Name = "xRange"
.Range("xRange").Insert Shift:=xlShiftDown

'' The MsgBox doesn't produce an expected result?
MsgBox "Address after shift " & newRange.Address
End With


End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Range.Insert query

Hi

When you use the constant xlShiftDown you are changing the row property
of the object newRange from 6 to 13.

newRange.Name = "xRange"
.Range("xRange").Insert Shift:=xlShiftDown

If you are trying to write a macro that shifts data around and then
produces a report I would first use the xlShiftDown and then reference
the desired range with a new variable.

Hope this helps

/ James

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
Insert subtotal in a query database Excel 2007 Scotty Tibbs II Excel Worksheet Functions 3 September 12th 09 12:50 AM
How Do I Query a Named Range JeffP-> Excel Worksheet Functions 2 February 3rd 09 11:11 PM
Searching a range with MS Query dsb Excel Worksheet Functions 3 November 1st 06 11:04 PM
External web query - insert rows Victoria Johnson via OfficeKB.com New Users to Excel 0 April 5th 05 10:15 PM
How update range after web query? Chris Shearer Cooper Excel Programming 2 May 10th 04 10:15 PM


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