Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 345
Default Object definition and structure, with variables

I tried to define an object representing a variable number
of rows that are to be cut and inserted into another sheet.
I got a type mismatch error on the code below.
In the module where this code is going to go,
the variables fromrow and to row are available and
'working'. I am a novice at 'object definition'.
Help will be appreciated.

Dim insertrange As range
Dim fromrow, torow As Integer

fromrow = 21: torow = 40

Set insertrange = Rows("&fromrow:&torow")

' Rows("21:40").Select trying to 'replace' this line of code
insertrange.Select 'with this line of code
Selection.Cut
Sheets("new").Select
range("A41").Select
Selection.Insert Shift:=xlDown

--
Neal Z
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Object definition and structure, with variables

Try

Set insertrange = Rows(fromrow&":"&torow)


--

HTH

RP
(remove nothere from the email address if mailing direct)


"Neal Zimm" wrote in message
...
I tried to define an object representing a variable number
of rows that are to be cut and inserted into another sheet.
I got a type mismatch error on the code below.
In the module where this code is going to go,
the variables fromrow and to row are available and
'working'. I am a novice at 'object definition'.
Help will be appreciated.

Dim insertrange As range
Dim fromrow, torow As Integer

fromrow = 21: torow = 40

Set insertrange = Rows("&fromrow:&torow")

' Rows("21:40").Select trying to 'replace' this line of code
insertrange.Select 'with this line of code
Selection.Cut
Sheets("new").Select
range("A41").Select
Selection.Insert Shift:=xlDown

--
Neal Z



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Object definition and structure, with variables

Neal,
Small point, but fromrow is declared as a Variant, whilst torow is an
Integer, which is not what you mean, I think.
You need to explicitly state the type of each variable, otherwise it
defaults to a Variant.
i.e. Dim fromrow as Integer
Dim torow As Integer

NickHK

"Neal Zimm" wrote in message
...
I tried to define an object representing a variable number
of rows that are to be cut and inserted into another sheet.
I got a type mismatch error on the code below.
In the module where this code is going to go,
the variables fromrow and to row are available and
'working'. I am a novice at 'object definition'.
Help will be appreciated.

Dim insertrange As range
Dim fromrow, torow As Integer

fromrow = 21: torow = 40

Set insertrange = Rows("&fromrow:&torow")

' Rows("21:40").Select trying to 'replace' this line of code
insertrange.Select 'with this line of code
Selection.Cut
Sheets("new").Select
range("A41").Select
Selection.Insert Shift:=xlDown

--
Neal Z



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 345
Default Object definition and structure, with variables

Wow, I thought that all variables in one row of code took on the meaning of
the 'as phrase' at the end of that line of code. (other languages do that).
Just to make 'deadly' sure, that means that a dim statement can have only one
variable following it, and that little fact must make for some long lists in
modules where there are a lot of variables. Please confirm, thanks, Neal


"Bob Phillips" wrote:

Try

Set insertrange = Rows(fromrow&":"&torow)


--

HTH

RP
(remove nothere from the email address if mailing direct)


"Neal Zimm" wrote in message
...
I tried to define an object representing a variable number
of rows that are to be cut and inserted into another sheet.
I got a type mismatch error on the code below.
In the module where this code is going to go,
the variables fromrow and to row are available and
'working'. I am a novice at 'object definition'.
Help will be appreciated.

Dim insertrange As range
Dim fromrow, torow As Integer

fromrow = 21: torow = 40

Set insertrange = Rows("&fromrow:&torow")

' Rows("21:40").Select trying to 'replace' this line of code
insertrange.Select 'with this line of code
Selection.Cut
Sheets("new").Select
range("A41").Select
Selection.Insert Shift:=xlDown

--
Neal Z




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 345
Default Object definition and structure, with variables

Yup, I misread the example in the Excel 'help' arena. The very first example
they give is Dim var1, var2 and then they talk about
both of them being variants.
Later in the example, where more than one var is in one line of code, there
IS an 'as' phrase following EACH var. Thanks much.

"NickHK" wrote:

Neal,
Small point, but fromrow is declared as a Variant, whilst torow is an
Integer, which is not what you mean, I think.
You need to explicitly state the type of each variable, otherwise it
defaults to a Variant.
i.e. Dim fromrow as Integer
Dim torow As Integer

NickHK

"Neal Zimm" wrote in message
...
I tried to define an object representing a variable number
of rows that are to be cut and inserted into another sheet.
I got a type mismatch error on the code below.
In the module where this code is going to go,
the variables fromrow and to row are available and
'working'. I am a novice at 'object definition'.
Help will be appreciated.

Dim insertrange As range
Dim fromrow, torow As Integer

fromrow = 21: torow = 40

Set insertrange = Rows("&fromrow:&torow")

' Rows("21:40").Select trying to 'replace' this line of code
insertrange.Select 'with this line of code
Selection.Cut
Sheets("new").Select
range("A41").Select
Selection.Insert Shift:=xlDown

--
Neal Z






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default Object definition and structure, with variables

each vaiable in a DIM statement must be specifically assigned a type or it
defaults to VARIANT

eg

DIM Index as integer, text as String, something, counter as long

in this statement the variable called 'something' will default to Variant.
Its better to be explicit in your code though, so this is better

DIM Index as integer, text as String, something as Variant, counter as long

this is the same as:
DIM Index as integer
DIM text as String
DIM something as Variant
DIM counter as long

Personally I go for the latter, since for me anyway, I find it easier to
debug or alter when I revisit months later.








"Neal Zimm" wrote:

Wow, I thought that all variables in one row of code took on the meaning of
the 'as phrase' at the end of that line of code. (other languages do that).
Just to make 'deadly' sure, that means that a dim statement can have only one
variable following it, and that little fact must make for some long lists in
modules where there are a lot of variables. Please confirm, thanks, Neal


"Bob Phillips" wrote:

Try

Set insertrange = Rows(fromrow&":"&torow)


--

HTH

RP
(remove nothere from the email address if mailing direct)


"Neal Zimm" wrote in message
...
I tried to define an object representing a variable number
of rows that are to be cut and inserted into another sheet.
I got a type mismatch error on the code below.
In the module where this code is going to go,
the variables fromrow and to row are available and
'working'. I am a novice at 'object definition'.
Help will be appreciated.

Dim insertrange As range
Dim fromrow, torow As Integer

fromrow = 21: torow = 40

Set insertrange = Rows("&fromrow:&torow")

' Rows("21:40").Select trying to 'replace' this line of code
insertrange.Select 'with this line of code
Selection.Cut
Sheets("new").Select
range("A41").Select
Selection.Insert Shift:=xlDown

--
Neal Z




  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Object definition and structure, with variables

And if you will store a row number in the variable, better to use a type
Long, or it might overflow.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"NickHK" wrote in message
...
Neal,
Small point, but fromrow is declared as a Variant, whilst torow is an
Integer, which is not what you mean, I think.
You need to explicitly state the type of each variable, otherwise it
defaults to a Variant.
i.e. Dim fromrow as Integer
Dim torow As Integer

NickHK

"Neal Zimm" wrote in message
...
I tried to define an object representing a variable number
of rows that are to be cut and inserted into another sheet.
I got a type mismatch error on the code below.
In the module where this code is going to go,
the variables fromrow and to row are available and
'working'. I am a novice at 'object definition'.
Help will be appreciated.

Dim insertrange As range
Dim fromrow, torow As Integer

fromrow = 21: torow = 40

Set insertrange = Rows("&fromrow:&torow")

' Rows("21:40").Select trying to 'replace' this line of code
insertrange.Select 'with this line of code
Selection.Cut
Sheets("new").Select
range("A41").Select
Selection.Insert Shift:=xlDown

--
Neal Z





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
Not at all clear on use of variables and/or object variables JMay-Rke Excel Discussion (Misc queries) 11 July 4th 08 06:36 PM
Multiple Variables in a Commission Structure...a tough one!!! Oriana G Excel Worksheet Functions 9 January 21st 06 07:52 PM
Not getting the object structure of VBA Excel Paul Excel Programming 5 January 28th 05 12:51 PM
Object variables scarbrough Excel Programming 3 December 6th 03 12:13 PM
Problem Using an Object Variable in a Class Definition Boxman Excel Programming 2 August 28th 03 03:05 AM


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