Solved

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

Posted on 2014-10-13
3
312 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 52

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 52

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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 …
Part One of the two-part Q&A series with MalwareTech.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Progress

617 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