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

Posted on 2014-10-13
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
Question by:llawrenceg
  • 2
LVL 48

Expert Comment

ID: 40377565

pls try

Sub Macro1()

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

Open in new window


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
End Sub

Open in new window

Hope this helps?
LVL 48

Accepted Solution

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", _
    myRange.Copy Range("E1")
End Sub


Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
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…

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now