+ Reply to Thread
Results 1 to 2 of 2

How to change and copy data position by Autofilter

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    03-31-2012
    Location
    Hong Kong
    MS-Off Ver
    Excel 2010
    Posts
    140

    How to change and copy data position by Autofilter

    I got the history data from Yahoo finance but some data have position bars error (i.e. High, Low, Close in disorder). I want to auto fix the bug by VBA but I haven't idea how to code, anyone could help me. Thanks.
    Attached Files Attached Files

  2. #2
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: How to change and copy data position by Autofilter

    Hi alee001

    See if this works for you
    Option Explicit
    
    Sub Macro1()
        Dim LR As Long
        Dim ws As Worksheet
        Dim x As Long
        Dim Rng As Range
        Dim cel As Range
        Dim OldE As Currency
        Dim OldD As Currency
        Dim OldC As Currency
        Dim NewE As Currency
        Dim NewD As Currency
        Dim NewC As Currency
    
        Set ws = Sheets("Data")
        With ws
            LR = .Cells.Find("*", .Cells(Rows.Count, .Columns.Count), SearchOrder:=xlByRows, _
                    SearchDirection:=xlPrevious).Row
            ActiveSheet.Range("A1:J" & LR).AutoFilter Field:=8, Criteria1:= _
                    "bar error"
            Set Rng = .Range("H2:H" & LR)
            x = Rng.Columns(8).SpecialCells(xlCellTypeVisible).Count
            If x >= 1 Then
                For Each cel In Rng.SpecialCells(xlCellTypeVisible)
    
                    OldE = .Range("E" & cel.Row).Value
                    OldC = .Range("C" & cel.Row).Value
                    OldD = .Range("D" & cel.Row).Value
                    NewE = OldC
                    NewC = OldD
                    NewD = OldE
                    .Range("E" & cel.Row).Value = OldD
                    .Range("C" & cel.Row).Value = OldE
                    .Range("D" & cel.Row).Value = OldC
                Next cel
            End If
        End With
    End Sub
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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