Solved

Excel 2003 copy only positive numbers of a list and paste to new column

Posted on 2014-10-13
3
260 Views
Last Modified: 2014-10-27
I have a list of positive and negative numbers in column C. I want to extract only the positive numbers to a new column E. A formula or VBA  for excel 2003 would be nice
0
Comment
Question by:llawrenceg
  • 2
3 Comments
 
LVL 49

Expert Comment

by:Rgonzo1971
ID: 40377565
Hi,

pls try

Sub Macro1()

    ActiveSheet.Range("A1:A100").AutoFilter Field:=1, Criteria1:=">0", _
        Operator:=xlAnd
    Range("A1:A100").Copy Range("E1")
    ActiveSheet.Range("A1:A100").AutoFilter
End Sub

Open in new window

Regards
0
 
LVL 2

Assisted Solution

by:Glen Richmond
Glen Richmond earned 100 total points
ID: 40379438
Hard coding the range ("A1:A100") will limit the scalability and dynamism of the code.. You need the code to dynamically adapt to more rows.
Mabye concatenate on the UsedRange.Rows.Count into Rgonzo's solution?

I just wrote this alternative that can be added to any module and tailored to use ..

Sub RemoveNegs()
    
    'set up obj var to sheet
    Dim wrkSht As Excel.Worksheet
    
    Dim intSource As Integer
    Dim intTarget As Integer
    
    'set up row e target row starting value
    intTarget = 1
    
    'set obj to sheet
    Set wrkSht = Application.Worksheets("Sheet1")
    
    'loop through all rows used
    For intSource = 1 To wrkSht.UsedRange.Rows.Count
        
        'is the number posertive?
        If wrkSht.Cells(intSource, "C").Value >= 0 Then
            
            'place value into target row E
            wrkSht.Cells(intTarget, "E").Value = wrkSht.Cells(intSource, "C").Value
            'add next row for target row (E)
            intTarget = intTarget + 1
        End If
        
    Next
    
End Sub

Open in new window


Hope this helps?
0
 
LVL 49

Accepted Solution

by:
Rgonzo1971 earned 400 total points
ID: 40379466
then try

Sub Macro1()
    Set myRange = Range("C1:C" & Range("C" & Rows.Count).End(xlUp).Row)
    myRange.AutoFilter Field:=1, Criteria1:=">0", _
        Operator:=xlAnd
    myRange.Copy Range("E1")
    myRange.AutoFilter
End Sub

Regards
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Report events not being triggered 8 120
Definitions and default visual studio colors 5 65
Android development question 2 37
VB.net and sql server 4 36
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question