Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 149
Default Passing a Cell Range

Below code deletes columns with empty cells in a certain range. Ideally, I'd
rather just pass "B" for example the used range instead of having to pass a
start and end cell for the range.

I'm getting error

Usage: Call DeleteEmptyColumnRange(A1, AM1)

Sub DeleteEmptyColumnRange(ByVal sBeginCell As String, ByVal sEndCell As
String)

Dim DelRange As Range
Dim c As Range

For Each c In ActiveSheet.Range(sBeginCell & ":" & sEndCell).Cells
If IsEmpty(c.Value) Then
If DelRange Is Nothing Then
Set DelRange = c.EntireColumn
Else
Set DelRange = Union(DelRange, c.EntireColumn)
End If
End If
Next c
'turn on error handling in case no range is assigned

On Error Resume Next
DelRange.Delete
On Error GoTo 0

End Sub



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 983
Default Passing a Cell Range

Here is my implimentation of your code passuing a range... I also cleaned up
the Delete as you don't really need the error handling.

Sub test()
DeleteEmptyColumnRange (ActiveSheet.Range("A1:AM1"))
End Sub

Public Sub DeleteEmptyColumnRange(ByVal rngToDelete As Range)

Dim DelRange As Range
Dim c As Range

For Each c In rngToDelete
If IsEmpty(c.Value) Then
If DelRange Is Nothing Then
Set DelRange = c.EntireColumn
Else
Set DelRange = Union(DelRange, c.EntireColumn)
End If
End If
Next c

If Not DelRange Is Nothing Then DelRange.Delete

End Sub


I think this is what you want.

HTH

"scott" wrote:

Below code deletes columns with empty cells in a certain range. Ideally, I'd
rather just pass "B" for example the used range instead of having to pass a
start and end cell for the range.

I'm getting error

Usage: Call DeleteEmptyColumnRange(A1, AM1)

Sub DeleteEmptyColumnRange(ByVal sBeginCell As String, ByVal sEndCell As
String)

Dim DelRange As Range
Dim c As Range

For Each c In ActiveSheet.Range(sBeginCell & ":" & sEndCell).Cells
If IsEmpty(c.Value) Then
If DelRange Is Nothing Then
Set DelRange = c.EntireColumn
Else
Set DelRange = Union(DelRange, c.EntireColumn)
End If
End If
Next c
'turn on error handling in case no range is assigned

On Error Resume Next
DelRange.Delete
On Error GoTo 0

End Sub




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
Passing a Range Jerry Excel Programming 4 February 14th 05 10:52 AM
Passing a range into a VBA function Floyd[_2_] Excel Programming 4 February 10th 05 01:29 AM
passing range to c# Jerry Excel Programming 0 January 29th 05 08:29 PM
Passing cell addressess to variables to be use in range ExcelMonkey[_146_] Excel Programming 2 June 11th 04 09:31 PM
Passing range to subprocedure - maybe? Mike Gerbracht Excel Programming 2 July 26th 03 02:44 AM


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