Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default Trying to create a custom "clear worksheet" function (in a VBA module)

I need to create a function that will, given a worksheet (passed byRef), and
given a start row, that will clear all of the cells from column D, and the
given row, all the way down (and right) to the bottom of the data. Then it
will select the first cell (column D, and the given starting row) and end
the function.

I've got something like that created, but every time I try to get it to
select from the first cell to the last, I get a "Application-defined or
object-defined error".

What am I missing?


The code is as follows:



Sub ClearWorksheet(ByRef ws As Worksheet, ByVal intStartRow As Integer)
Dim tempString As String

tempString = "D" & CStr(intStartRow)
ws.Range(tempString,
Application.ActiveCell.SpecialCells(xlLastCell)).S elect ' This is the line
giving me the Application-defined error

Selection.ClearContents
ws.Range("D" & CStr(intStartRow)).Select

End Sub



Thanks!
-Scott


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default Trying to create a custom "clear worksheet" function (in a VBA module)

Oh, one more thing I forgot to add. The reason I need this custom "clear
worksheet" function/sub (rather than using built-in functions to clear the
whole worksheet), is that I have quite a bit of header information that goes
in the left-most 3 columns, as well as the first 11-30 lines (it varies how
many, depending on the worksheet). If I clear the whole sheet, I'd lose all
of that (which I do not wish to do).


Hope this clears it up a little.

-Scott


"Scott Lyon" <scott.lyonNOSPAM_at__NOSPAMrapistan.comNOSPAM wrote in
message ...
I need to create a function that will, given a worksheet (passed byRef),

and
given a start row, that will clear all of the cells from column D, and the
given row, all the way down (and right) to the bottom of the data. Then it
will select the first cell (column D, and the given starting row) and end
the function.

I've got something like that created, but every time I try to get it to
select from the first cell to the last, I get a "Application-defined or
object-defined error".

What am I missing?


The code is as follows:



Sub ClearWorksheet(ByRef ws As Worksheet, ByVal intStartRow As Integer)
Dim tempString As String

tempString = "D" & CStr(intStartRow)
ws.Range(tempString,
Application.ActiveCell.SpecialCells(xlLastCell)).S elect ' This is the

line
giving me the Application-defined error

Selection.ClearContents
ws.Range("D" & CStr(intStartRow)).Select

End Sub



Thanks!
-Scott




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
Create Pivot Table Data with Column "Sum" rather than "count" defa Johnny_99[_2_] Excel Discussion (Misc queries) 2 January 2nd 10 03:25 PM
How do I search a worksheet for a custom "text" max and min value Joe Lewis[_2_] Excel Discussion (Misc queries) 1 November 18th 08 01:56 PM
Macro to Create New Worksheet and Reference Cell in Old Worksheet As Tab Name - "Object Required" Error [email protected] Excel Discussion (Misc queries) 4 September 25th 06 01:35 PM
create links to check boxes marked "good" fair"and "bad" pjb Excel Worksheet Functions 3 April 20th 06 02:17 AM
Adding a "CLEAR" button to the worksheet Billy Excel Discussion (Misc queries) 1 January 8th 06 06:09 PM


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