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.
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.
Hi alee001
See if this works for youOption 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.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks