Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 201
Default Error selecting range from userform

In the code behind a userform I have tried to clear the contents of some
cells, but I get a 1001 error.


With ActiveWorkBook.Sheets(LoadSheet).Range(Cells(RowSe l, "B"),
Cells(RowSel_TLA , "BA"))
.ClearContents
End With

The above works from a normal module, but will not run from a worksheet or a
userform. If there something else I can do to achieve the same thing?

--
Trefor
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Error selecting range from userform


The problem is that the "Cells" reference doesn't refer to the sheet
LoadSheet. If refers to whatever worksheet happens to be active. If
LoadSheet isn't active, the code will fail. Try instead,

With ActiveWorkbook.Sheets(LoadSheet)
.Range(.Cells(RowSel, "B"), _
.Cells(RowSel_TLA, "BA")).ClearContents
End With

Here, the Cells references are adorned with a period, which makes them
"roll up" through the LoadSheet rather than the ActiveSheet.

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)



On Thu, 6 Nov 2008 07:22:00 -0800, Trefor wrote:

In the code behind a userform I have tried to clear the contents of some
cells, but I get a 1001 error.


With ActiveWorkBook.Sheets(LoadSheet).Range(Cells(RowSe l, "B"),
Cells(RowSel_TLA , "BA"))
.ClearContents
End With

The above works from a normal module, but will not run from a worksheet or a
userform. If there something else I can do to achieve the same thing?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 201
Default Error selecting range from userform

Chip,

Silly me. Many thanks.

--
Trefor


"Chip Pearson" wrote:


The problem is that the "Cells" reference doesn't refer to the sheet
LoadSheet. If refers to whatever worksheet happens to be active. If
LoadSheet isn't active, the code will fail. Try instead,

With ActiveWorkbook.Sheets(LoadSheet)
.Range(.Cells(RowSel, "B"), _
.Cells(RowSel_TLA, "BA")).ClearContents
End With

Here, the Cells references are adorned with a period, which makes them
"roll up" through the LoadSheet rather than the ActiveSheet.

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)



On Thu, 6 Nov 2008 07:22:00 -0800, Trefor wrote:

In the code behind a userform I have tried to clear the contents of some
cells, but I get a 1001 error.


With ActiveWorkBook.Sheets(LoadSheet).Range(Cells(RowSe l, "B"),
Cells(RowSel_TLA , "BA"))
.ClearContents
End With

The above works from a normal module, but will not run from a worksheet or a
userform. If there something else I can do to achieve the same thing?


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
Error when selecting date range. [email protected] Excel Programming 4 July 16th 08 04:39 PM
Help selecting a range in vba from userform inputs grievesy[_3_] Excel Programming 3 April 27th 06 10:28 PM
User selecting range from userform via dropdown menue mslabbe Excel Programming 2 July 10th 04 05:16 PM
1004 error when selecting a range Matt J[_2_] Excel Programming 9 July 3rd 04 10:05 PM
Error 1004 when selecting a range Matt J Excel Programming 1 July 3rd 04 06:50 PM


All times are GMT +1. The time now is 06:19 PM.

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"