Results 1 to 3 of 3

ForEach loop problem

Threaded View

peterschein ForEach loop problem 05-27-2019, 01:10 PM
mrice Re: ForEach loop problem 05-27-2019, 01:16 PM
Fluff13 Re: ForEach loop problem 05-27-2019, 01:24 PM
  1. #1
    Forum Contributor
    Join Date
    10-26-2018
    Location
    Vienna, Austria
    MS-Off Ver
    2016 professional
    Posts
    154

    ForEach loop problem

    Dear Users,



    my goal is to copy all of the numbers from the "copyPaste" sheet to the other sheet which are between 41000000 and 42000000.

    If I run the code below it only gives the last value that is between these two. (it is also very slow...)

    Can you spot the mistake?

    (since I am a rooky I would learn the most if there would be as many changes as it is necessary if you add to it.. the goal is mainly to know my mistake than realy get the values)

    Sub ForEach()
    
    
    ActiveWorkbook.Worksheets("copypaste").Select
    
        Dim lastRow As Range
        Dim SelectRange As Range
        Dim cell As Range
        
    
            Set lastRow = Cells(Rows.Count, 3).End(xlUp)
            Set SelectRange = ActiveWorkbook.Worksheets("copypaste").Range("C3", lastRow)
            
        For Each cell In SelectRange
        
            If cell > 41000000 And cell < 42000000 Then
            
            cell.Copy ActiveWorkbook.Worksheets("forEach").Range("a" & Rows.Count).End(xlUp)
            
            
        End If
        
        Next cell
        
        Worksheets("forEach").Select
        
       
    End Sub

    Thank you indeed for your time and help

    please see attachment
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Convert data (a bit like a FOREACH?)
    By simonp820 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-04-2016, 03:32 PM
  2. Excel 2007 Sumproduct foreach day in column?
    By jrider64 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 07-29-2015, 02:27 PM
  3. Foreach Name in a List Paste a Template of Cells
    By Codeman553 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-03-2013, 10:25 AM
  4. [SOLVED] Foreach loop lookup between two worksheets
    By asparak in forum Excel General
    Replies: 7
    Last Post: 07-14-2012, 05:03 AM
  5. Replies: 2
    Last Post: 06-25-2012, 12:24 PM
  6. [SOLVED] ForEach statement problem
    By excelnut1954 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-31-2006, 05:40 PM
  7. Problem adding charts using Do-Loop Until loop
    By Chris Bromley in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-23-2005, 09:06 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1