Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 573
Default Won't insert value

I'm copying the contents of a cell in Sheet "B" to a cell in Sheet "A",
but the program hangs when I try to put the value in "A". The command
I'm using is:

Worksheets("A").Range(iCurRow, 1).Value = strCurID

The iCurRow value checks out correctly, as does the strCurID. What's
wrong with this code?
Thanks for the help.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Won't insert value

Dave,

Range doesn't take numeric values, only strings. Cells uses row/col
numbers.

Use:
Worksheets("A").Cells(iCurRow, 1).Value = strCurID

HTH,
Bernie
MS Excel MVP

"davegb" wrote in message
oups.com...
I'm copying the contents of a cell in Sheet "B" to a cell in Sheet "A",
but the program hangs when I try to put the value in "A". The command
I'm using is:

Worksheets("A").Range(iCurRow, 1).Value = strCurID

The iCurRow value checks out correctly, as does the strCurID. What's
wrong with this code?
Thanks for the help.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Won't insert value

Oh, if you want to use the Range object with your iCurRow, you would need to
use

Worksheets("A").Range("A" & iCurRow).Value = strCurID

HTH,
Bernie
MS Excel MVP

"Bernie Deitrick" <deitbe @ consumer dot org wrote in message
...
Dave,

Range doesn't take numeric values, only strings. Cells uses row/col
numbers.

Use:
Worksheets("A").Cells(iCurRow, 1).Value = strCurID

HTH,
Bernie
MS Excel MVP

"davegb" wrote in message
oups.com...
I'm copying the contents of a cell in Sheet "B" to a cell in Sheet "A",
but the program hangs when I try to put the value in "A". The command
I'm using is:

Worksheets("A").Range(iCurRow, 1).Value = strCurID

The iCurRow value checks out correctly, as does the strCurID. What's
wrong with this code?
Thanks for the help.





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 573
Default Won't insert value

Bernie,
Thanks for your reply. I'm still confused. In your first reply, you
said, "Range doesn't take numeric values, only strings. Cells uses
row/col numbers." In your second message, you show how to use Range to
take a numeric value. Can you elucidate further?
I'm new to VBA programming and am finding it far more confusing than
any other programming language I've ever learned. Granted, it's been a
lone time and none of the older languages were object oriented, so I'm
trying to accept that everything I ever knew about programming is worse
than useless. It's misleading!
I can't seem to figure out when to use Cells and when to use Range, or
when to use Worksheet, Worksheets, and Sheets. There seem to be an
awful lot of different things to represent the same thing. I know you
didn't invent VBA, and it's not your fault, but it sure is strange. Any
ideas or guidlines as to when to use which of the many similar objects?

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Won't insert value

Dave,

I'm sorry. In my second example, Excel coerces the value of the integer
variable into a string due to the concantenation operation:

"A" & iCurRow

will result in a string "A1" (if iCurRow is 1 at the time). So Range ends
up being passed a string.

Which method or property is best to use depends on what you want to do, and
what you have. Sheets is a collection of all sheets, including chart sheets
and worksheets, and worksheets is a collection of only worksheets. So which
is better depends.....

Experience is the best teacher, with posting here (or just reading the
posts) a close second. Also, get a good book: Excel Power Programming with
VBA by John Walkenbach is an excellent resource for the beginning VBA coder.
And use your macro recorder to generate code that you can edit. And just get
in there and do it....

HTH,
Bernie
MS Excel MVP

"davegb" wrote in message
ups.com...
Bernie,
Thanks for your reply. I'm still confused. In your first reply, you
said, "Range doesn't take numeric values, only strings. Cells uses
row/col numbers." In your second message, you show how to use Range to
take a numeric value. Can you elucidate further?
I'm new to VBA programming and am finding it far more confusing than
any other programming language I've ever learned. Granted, it's been a
lone time and none of the older languages were object oriented, so I'm
trying to accept that everything I ever knew about programming is worse
than useless. It's misleading!
I can't seem to figure out when to use Cells and when to use Range, or
when to use Worksheet, Worksheets, and Sheets. There seem to be an
awful lot of different things to represent the same thing. I know you
didn't invent VBA, and it's not your fault, but it sure is strange. Any
ideas or guidlines as to when to use which of the many similar objects?





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 573
Default Won't insert value

Thanks Bernie! It sort of makes sense. It's going to take some time to
figure out a whole new paradigm for me in programming.

"Sheets is a collection of all sheets, including chart sheets and
worksheets, and worksheets is a collection of only worksheets."
Does that mean that if there are no charts present, Sheets and
Worksheets would be the same thing? Or is there still a difference?

"Experience is the best teacher, with posting here (or just reading the

posts) a close second. Also, get a good book: Excel Power Programming
with
VBA by John Walkenbach is an excellent resource for the beginning VBA
coder.
And use your macro recorder to generate code that you can edit. And
just get
in there and do it.... "

Actually, that's exactly what I've been doing. I got Walkenbach's book
last week, and I agree that it's a good one.
Thanks again,
Dave

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 row / insert column command buttons fairgreen Excel Worksheet Functions 1 October 29th 07 02:41 PM
How can I insert a date with an icon (calendar) insert Alfredo Mederico[_2_] Excel Discussion (Misc queries) 4 September 21st 07 01:20 AM
Can I auto insert a worksheet when I insert a value in a cell. iainc Excel Worksheet Functions 0 April 27th 06 08:37 AM
Insert Next? Or insert a variable number of records...how? Tom MacKay Excel Discussion (Misc queries) 0 April 20th 06 10:44 PM
Insert cell/format/text/fontsize and auto insert into header? Unfurltheflag Excel Programming 2 November 3rd 04 05:39 PM


All times are GMT +1. The time now is 07:43 AM.

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"