Thread: Macro help
View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Per Jessen[_2_] Per Jessen[_2_] is offline
external usenet poster
 
Posts: 703
Default Macro help

Hi

The problem is word wrapping in your news reader.

Place the cursor at the end of the first red line and hit Delete to
delete the line feed. Move on to the next line.

Hopes it helps

---
Per

On 18 Dec., 14:33, Gemz wrote:
Hi,

Thanks for your reply. i put the code in and it already it highlighted 3
rows in red and i didnt know how to fix:

*1 - NumCols = WorksheetFunction.CountA(Range("C3", Range("C3").End
(xlToRight)))

2 - If WorksheetFunction.Sum(StartCol.Offset(0, i).EntireColumn) = 0
Then

3 - Set ColArray = Union(ColArray, StartCol.Offset(0,
i).EntireColumn)

thanks.



"Joshua Fandango" wrote:
Hi Gemz,


The following starts from cell C3 (change if necessary e.g. all "C3"s
to "B2" if that's where the data starts), counts the number of columns
to use from C3 to the right (can't handle any blank cells), tests if
the sum of the column in question = 0 and if so adds it into an array
which is deleted once all columns have been tested.


The array is necessary to catch instances where 2 or more sequential
columns sum 0.


Option Explicit
Sub Delete_Zero_Columns()
Dim NumCols As Integer, i As Integer
Dim StartCol As Range, ColArray As Range
* Set StartCol = Range("C3")
* NumCols = WorksheetFunction.CountA(Range("C3", Range("C3").End
(xlToRight)))


* For i = 0 To NumCols - 1
* * If WorksheetFunction.Sum(StartCol.Offset(0, i).EntireColumn) = 0
Then
* * * If ColArray Is Nothing Then
* * * * Set ColArray = StartCol.Offset(0, i).EntireColumn
* * * Else
* * * * Set ColArray = Union(ColArray, StartCol.Offset(0,
i).EntireColumn)
* * * End If
* * End If
* Next i
* ColArray.Delete
End Sub


HtH,
JF.


On 18 Dec, 10:51, Gemz wrote:
Hi,


Hope u can help me with the below:


I have a spreadsheet which is exported from a system with a whole lot of 0’s
that don’t need to be there.


So, the condition is – if the contents of C3 down, D3 down, E3 down etc
contains ALL 0 then delete entire column. The spreadsheet spans from about C3
to AH onwards (however the spreadsheet can grow smaller or bigger at any time
so its not good to specify an end column). I need to have this for all the
columns i.e. F3 down, G3 down etc etc.


So, all i want it to do is look from cell 3 downwards in each column and if
the contents of each column it is ALL 0 then to delete the entire column.


I hope this is making sense, what i want isn’t so hard but its not easy to
say it!


Thanks for help.- Skjul tekst i anførselstegn -


- Vis tekst i anførselstegn -