Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default inserted code into project but can't run it in run dialogbox

I started a new Excel document with arbitrary column
heading with some actually having data in that column.
I went to toolsmacro VBA editor
created a new module pasted this code in:

(it deletes columns having no data in them)


Public Sub GetRidofEmptyColumns(DeleteRange As Range)
Dim cCount As Integer, c As Integer
If DeleteRange Is Nothing Then Exit Sub
If DeleteRange.Areas.Count 1 Then Exit Sub
With DeleteRange
cCount = .Columns.Count
For c = cCount To 1 Step -1
If Application.CountA(.Columns(c)) = 0 Then
.Columns(c).EntireColumn.Delete
End If
Next c
End With
End Sub

How to I get this to run?
thank you,
den
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default inserted code into project but can't run it in run dialogbox

Since you macro requires an argument, it isn't shown.

You might want to modify it to

Public Sub GetRidofEmptyColumns()
Dim cCount As Integer, c As Integer
Dim DeleteRange as Range
set DeleteRange = Selection.EntireColumn
If DeleteRange Is Nothing Then Exit Sub
If DeleteRange.Areas.Count 1 Then Exit Sub
With DeleteRange
cCount = .Columns.Count
For c = cCount To 1 Step -1
If Application.CountA(.Columns(c)) = 0 Then
.Columns(c).EntireColumn.Delete
End If
Next c
End With
End Sub

This will work on the selected columns and can be run from
Tools=Macro=Macros dialog.

Otherwise you could keep the original and call it from another macro

Public Sub CleanColumns()
GetRidofemptyColumns Selection.Entirecolumn
End Sub

--
Regards,
Tom Ogilvy


cpudenusa wrote in message
...
I started a new Excel document with arbitrary column
heading with some actually having data in that column.
I went to toolsmacro VBA editor
created a new module pasted this code in:

(it deletes columns having no data in them)


Public Sub GetRidofEmptyColumns(DeleteRange As Range)
Dim cCount As Integer, c As Integer
If DeleteRange Is Nothing Then Exit Sub
If DeleteRange.Areas.Count 1 Then Exit Sub
With DeleteRange
cCount = .Columns.Count
For c = cCount To 1 Step -1
If Application.CountA(.Columns(c)) = 0 Then
.Columns(c).EntireColumn.Delete
End If
Next c
End With
End Sub

How to I get this to run?
thank you,
den



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default inserted code into project but can't run it in run dialogbox


I will try this thank you for the reply



-----Original Message-----
I started a new Excel document with arbitrary column
heading with some actually having data in that column.
I went to toolsmacro VBA editor
created a new module pasted this code in:

(it deletes columns having no data in them)


Public Sub GetRidofEmptyColumns(DeleteRange As Range)
Dim cCount As Integer, c As Integer
If DeleteRange Is Nothing Then Exit Sub
If DeleteRange.Areas.Count 1 Then Exit Sub
With DeleteRange
cCount = .Columns.Count
For c = cCount To 1 Step -1
If Application.CountA(.Columns(c)) = 0 Then
.Columns(c).EntireColumn.Delete
End If
Next c
End With
End Sub

How to I get this to run?
thank you,
den
.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default inserted code into project but can't run it in run dialogbox

You need to be able to pass the argument into
deletedrange. You could write a macro to do it, example

Sub testit()
Call GetRidofEmptyColumns(Selection)
End Sub


Lance
-----Original Message-----
I started a new Excel document with arbitrary column
heading with some actually having data in that column.
I went to toolsmacro VBA editor
created a new module pasted this code in:

(it deletes columns having no data in them)


Public Sub GetRidofEmptyColumns(DeleteRange As Range)
Dim cCount As Integer, c As Integer
If DeleteRange Is Nothing Then Exit Sub
If DeleteRange.Areas.Count 1 Then Exit Sub
With DeleteRange
cCount = .Columns.Count
For c = cCount To 1 Step -1
If Application.CountA(.Columns(c)) = 0 Then
.Columns(c).EntireColumn.Delete
End If
Next c
End With
End Sub

How to I get this to run?
thank you,
den
.

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
Searching Multiple Timesheets for a project code and then.... Saitei Excel Worksheet Functions 1 May 26th 10 08:11 AM
reactivate DialogBox oldLearner57 Excel Discussion (Misc queries) 1 September 15th 08 01:02 AM
Dialogbox Creation Scott Excel Discussion (Misc queries) 0 May 6th 06 09:52 PM
Exel dialogbox/dialogboks Anders Mortensen Excel Discussion (Misc queries) 1 January 18th 06 06:46 PM
OpenFile dialogbox Manu Palao Excel Worksheet Functions 1 November 24th 04 04:27 PM


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