Re: Move Non Zero Columns Left?



Thanks very much, Rich!

I'll try this first thing Tuesday.

Patrick

On Jan 16, 4:47 pm, Rich P <rpng...@xxxxxxx> wrote:
I think I get it now.  To automate this will require a little bit of
coding.  First set up your spreadsheet by creating a similar set of data
directly adjacent to your current set:  Ex -- in the spreadsheet you
currently have the following columns

A      B C D E F G H I J k l  M   N   O
Fred   0 0 0 3 9 7 0 0 5 9   | | | | | | ...

..

Starting at column M create the same borders as you have in the first
set and set the values all to 0 -- use the Accounting format if you want
- dashes in place of 0.  Then in the Visual Basic Editor we will add a
subroutine that will copy only numbers in each row which are greater
than 0 to adjacent cells on the same row.  In the Tools Menu goto Macro
to Visual Basic Editor.  Now insert a code module in the project from
the Insert menu.  Copy this routine into the module

Sub CopyNumbers()
Dim rng As Range, i As Integer, j As Integer, k As Integer
set rng = Range("B1:K10, M1:V10)
For i = 1 To rng.Areas(1).Rows.Count
  k = 1
  For j = 1 To rng.Areas(1).Columns.Count
    If rng.Areas(1)(i, j) <> 0 Then
       rng.Areas(2)(i, k) = rng.Areas(1)(i, j)
       k = k + 1
    End If
  Next
Next
End Sub

To experiment with this code do this:  In a blank sheet in the same
Excel File add some fake data starting at row1 "A1" as above.  Add Fred
and some numbers with 0's starting at column B to column K.  Then add
Barney on row2, Wilma row3, ... don't even bother with borders- we are
just testing out the routine.  Add 10 rows of data because I have set my
range object to read 10 rows of data.  Make sure to intersperse some 0's
in your 10 rows.  What the routine above will do is to read the 10 rows
and copy only the non zero numbers to a 2nd range which will be adjacent
to the first set starting at column M.  

Now go back to the Tools menu in your sheet and goto Macro then select
Macros.  You will see the CopyNumbers macro in the list.  It should be
highlighted.  Click the Run button and watch what happens.  All the
numbers which are greater than zero will get copied to the cells
starting at M.  This routine can copy 10,000 rows the same way in a
matter of seconds.  Way better than doing it by hand.

Rich

*** Sent via Developersdexhttp://www.developersdex.com***

.



Relevant Pages

  • Re: Unable to use the interval timer
    ... I need your help with a routine I'm unable to write properly. ... I want to use the Interval Timer which, unless I'm wrong, is the only ... MOV   R0,#&10 ... ADR   R1,Code_Timer ...
    (comp.sys.acorn.programmer)
  • Re: Newly getting started in C#
    ... In VB I would create the connection to the database and connect to it ... put the connection routine in the program.cs module? ... Scott Roberts    Visa profil ... namespace MyDAL ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Child process does not inherit parents working library
    ... additional BCI Job if the referred JOBD of SBMJOB has ALWMLTTHD, ...     JOB ... parent's (which I have set manually via the CURLIB parameter). ... As a contribution to the group, here is a C++ routine to get the ...
    (comp.sys.ibm.as400.misc)
  • Re: A "simple" routine used in 30-odd programs which is probably wrong!
    ... routine, all which are very very similar, but which differ in ... C    OBJECT: TO CALCULATE ... C LABEL 100 USES RESULT. ... one of the expressions is incorrect.. ...
    (comp.lang.fortran)
  • Re: inspiration
    ...    'Routine' is not 'ritual'. ... writer to professional levels, and two, you may someday get to a point ... I actively dislike routine. ... I read a lot when I'm not writing. ...
    (rec.arts.sf.composition)