Consulting

Results 1 to 4 of 4

Thread: Value change with date

  1. #1

    Value change with date

    Helloo

    Is there any way that if in one coloum i have more than 2500 numbers and i have put the conditional values that if the value is grater than 500 the cell color should be red. this farmula works fine. Now the matter is red color cell should copy to the next sheet with complete row data.

    Is there any way in VBA

    Thanks

    Bobby

  2. #2
    Moderator VBAX Master georgiboy's Avatar
    Joined
    Mar 2008
    Location
    Kent, England
    Posts
    1,198
    Location
    This should do it it you adjust it to your ranges and sheet names
    [VBA]Sub MoveRow()
    Sheets("Sheet1").Range("A1").Activate
    Do While ActiveCell.Value <> ""
    If ActiveCell.Value > 500 Then
    ActiveCell.EntireRow.Copy
    ActiveCell.Offset(1, 0).Activate
    Sheets("Sheet2").Select
    Range("A1").Select
    Do While ActiveCell.Value <> ""
    ActiveCell.Offset(1, 0).Select
    Loop
    ActiveCell.PasteSpecial xlPasteValuesAndNumberFormats
    Sheets("Sheet1").Activate
    Else
    ActiveCell.Offset(1, 0).Activate
    End If
    Loop

    End Sub[/VBA]

    Hope this helps

  3. #3
    Thank you georgiboy really its work fine
    thank you

  4. #4
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Hi Georgi,
    While the loop works, it can be slow for a lot of data. You can speed it up be avoiding selecting as
    [VBA]
    Option Explicit
    Sub MoveRow()
    Dim Tgt As Range, cel As Range
    Dim i As Long

    Application.ScreenUpdating = False

    Set Tgt = Sheets(2).Cells(Rows.Count, 1).End(xlUp)
    With Sheets(1)
    For Each cel In Range(Cells(1, 1), Cells(Rows.Count, 1).End(xlUp))
    If cel > 500 Then
    i = i + 1
    cel.EntireRow.Copy
    Tgt.Offset(i).PasteSpecial xlAll
    End If
    Next
    End With
    Application.ScreenUpdating = True

    End Sub
    [/VBA]

    Better still, apply a filter for this sort of procedure. Very much quicker.
    [VBA]
    Option Explicit
    Sub FilterData()
    With Sheets(1)
    .Columns("A:A").AutoFilter Field:=1, Criteria1:=">500"
    .UsedRange.SpecialCells(xlCellTypeVisible).Copy
    Sheets(3).Range("A1").PasteSpecial xlAll
    .Columns("A:A").AutoFilter
    End With
    End Sub

    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

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