ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Run-time errors (https://www.excelbanter.com/excel-programming/273148-re-run-time-errors.html)

Tom Lambert

Run-time errors
 
Hi Rob,

(Thanks also to Tom Ogilvy for your response on this
matter which may highlight potential problems - as a newby
I originally searched for a response via my ISP server &
this was not accessible after a short period of time. I
now know how to access directly from the MS site).

Unfortunately my code is riddled with applucations of the
Select method.

A simple example of how I invoke this is as follows:

Public Sub GetClientMap()
Dim SectRng, MapRng As Range

Range(MapRng(2, 1), MapRng(MapRng.Rows.Count - 1,
MapRng.Columns.Count)).Copy
SectRng(2, 1).Select
ActiveSheet.Paste
End Sub

Are you suggesting I should convert the range contents to
an array or some other method?

Thanks in anticipation,

Tom
-----Original Message-----
Hi Tom,

The best way to prevent this error is not to use the

Select method in
your code. There are almost no situations in VBA that

require you to
explicitly select a cell. Everyone starts out coding this

way because that's
how the macro recorder does it, but it's not really the

best way to do
things. If you post an example of code that's giving you

problems, I'm sure
we can show you how to rewrite it sans Select.

--
Rob Bovey, MCSE, MCSD, Excel MVP
Application Professionals
http://www.appspro.com/

* Please post all replies to this newsgroup *
* I delete all unsolicited e-mail responses *


"tielle" wrote in message
...
I have recurring problems with Run-time errors (1004)

with the message
'Select Method of Range Class failed' when using the

Select method on a
Range object within Excel VBA macros.

The same code works successfully many times but seems

to trip up
unexpectedly.

Does anyone have a smart way of avoiding this or can

hint as to how it
might
be occurring? I know for instance it has greater risk

of occurring when a
proedure is run from within the VBE editor than say a

control button in
the
workbook.

Regards,
--

Tom Lambert





.



All times are GMT +1. The time now is 11:58 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com