返回列表 上一主題 發帖

[發問] 資料排序反轉

[發問] 資料排序反轉

這是用巨集錄的資料排序反轉
請問有簡單的寫法
如何解除鎖定工作列

謝謝

IsSort.rar (648.38 KB)

本帖最後由 wufonna 於 2013-10-5 10:22 編輯

又請問我想畫出河流圖,參考 c_c_lai 大的
http://forum.twbts.com/thread-6531-1-1.html
如何錯誤,謝謝

2013-10-05_101137.jpg (131.75 KB)

2013-10-05_101137.jpg

IsSort2.rar (658.3 KB)

TOP

回復 2# wufonna
試試看!

IsSort2.rar (817.56 KB)
解決方法如下:
1.  .SetSourceData Source:=Range("data!$A$4:data!$A$" & totalRows & ", data!$B$4:data!$E$" & totalRows)
     出現錯誤訊息; 但不予理會,其問題是因 totalRows 值 = 3075 (超出 255) 所引發。
2.  在 ActiveSheet.Shapes.AddChart.Select 上一行, 故意補上一行: (輸入)
     totalRows = 100
     然後、再重新執行 drawCharts(), 待正常繪出圖表後再將 totalRows = 100 那一行刪除掉,再執行 drawCharts,
     之後便一切 OK 解決了。至於為何會出現此錯誤訊息,可能要請教各位前賢了!
3.  祝順意!

TOP

謝謝 c_c_lai  大大
這是改過的檔案

請問如何加入縱的格線,下面的日期顯示幾年一月,隱藏數列1 數列2 數列3 數列4
6,783.3 改成 第四列的 1.12 1.09 1.06 1.03 1 0.97 0.94 0.91 0.88
如下面的圖例,謝謝

下面的 vba 有簡單的寫法嗎

'取得圖表的最大、最小值
Sub GetMinMax()
    With Sheets("data")
        Dim VMin As Single, VMax As Single
        Dim VIMin As Single, VIMax As Single
        Dim i As Integer
        
        
        
        VMin = .Cells(5, 9).Value
        VMax = .Cells(5, 9).Value
        
        'Debug.Print "VMin =" & VMin
        'Debug.Print "VMax =" & VMax
            For i = 5 To .Range("I" & .Rows.Count).End(xlUp).Row
                If .Cells(i, 9).Value < VMin Then
                    VMin = .Cells(i, 9).Value
'                    Debug.Print "VMin =" & VMin
'                    Debug.Print i
                    GoTo NNN
                End If
               
                If .Cells(i, 9).Value > VMax Then
                    VMax = .Cells(i, 9).Value
'                    Debug.Print "VMax =" & VMax
'                    Debug.Print i
                End If
NNN:
            
            Next
'        Debug.Print "VMin =" & VMin
'        Debug.Print "VMax =" & VMax
        VIMin = Int(VMin * 0.88 / 1000) * 1000
        VIMax = Int(VMax * 1.12 / 1000) * 1000 + 1000
'        Debug.Print VIMin
'        Debug.Print VIMax
   
   
    End With
End Sub

圖例的股價最小 VIMin,最大值 VIMax vba 如何 寫 謝謝

Mychart.gif (51.17 KB)

Mychart.gif

IsSort2.rar (902.69 KB)

TOP

本帖最後由 stillfish00 於 2013-10-9 16:00 編輯

回復 4# wufonna
下面的 vba 有簡單的寫法嗎
  1.     With Sheets("data")
  2.       VIMin = Int(Application.WorksheetFunction.Min(.Range(.[I5], .[I5].End(xlDown))) * 0.88 / 1000) * 1000
  3.       VIMax = Int(Application.WorksheetFunction.Max(.Range(.[I5], .[I5].End(xlDown))) * 1.12 / 1000) * 1000 + 1000
  4.     End With
複製代碼

TOP

謝謝 stillfish00  大大
小弟對vba圖表的指令/__\
圖好像沒作用,不知指令下在那


Option Explicit

Sub drawCharts()
    Dim toindexRows As Single, totalRows As Single, totalRows2 As Single

    Dim xRow, yCol, cHeight, cWidth As Integer
    Dim text As String
    Dim chartname As String
    Dim sRowHeight As Single
    Dim VIMin As Single, VIMax As Single
    xRow = 3
    yCol = 1
    cHeight = 31         'CHeight 定義為圖表所佔的列高
    cWidth = 874

    With Sheets("data")
      VIMin = Int(Application.WorksheetFunction.Min(.Range(.[I5], .[I5].End(xlDown))) * 0.88 / 1000) * 1000
      VIMax = Int(Application.WorksheetFunction.Max(.Range(.[I5], .[I5].End(xlDown))) * 1.12 / 1000) * 1000 + 1000
    End With
   
    Sheets("chart").Select

   ActiveSheet.ChartObjects.Delete
    toindexRows = Sheets("data").Range("I" & Rows.Count).End(xlUp).Row - 1100      '約取三年資料
    totalRows = Sheets("data").Range("A" & Rows.Count).End(xlUp).Row     ' 傳回 B 欄所使用儲存格之最後一格之列號
      totalRows2 = Sheets("data").Range("I" & Rows.Count).End(xlUp).Row     ' 傳回 I 欄所使用儲存格之最後一格之列號
'    '先把列高找出來, 才好算出圖要佔幾列, 兩個圖才好連在一起
'    sRowHeight = Sheets("data").Rows(3).RowHeight

    ActiveSheet.Shapes.AddChart.Select
    With ActiveChart
        .SetSourceData Source:=Range("data!$A$" & toindexRows & ":data!$A$" & totalRows2 & ", data!$B$" & toindexRows & ":data!$E$" & totalRows2)
Debug.Print totalRows
        .ChartType = xlStockOHLC
        With .ChartGroups(1)
             .AxisGroup = 1
             ' .UpBars.Format.Fill.ForeColor.RGB = RGB(255, 0, 0)           ' 紅色
             .UpBars.Format.Fill.ForeColor.RGB = RGB(255, 69, 0)          ' 橘紅色
             ' .DownBars.Format.Fill.ForeColor.RGB = RGB(0, 32, 96)       ' 深藍色
             .DownBars.Format.Fill.ForeColor.RGB = RGB(0, 250, 170)     ' 淺洋綠色
        End With

            .SeriesCollection.Add Source:=Range("data!$J$" & toindexRows & ":data!$R$" & totalRows2)
'             .SeriesCollection.Add Source:=Range("data!$J$" & toindexRows & ":data!$R$" & totalRows)

Debug.Print totalRows


        With .SeriesCollection(5)
            .Name = "=data!$J$" & toindexRows
            .ChartType = xlLine
            With .Format.Line
                .Visible = msoTrue          ' 主力界入
                ' .ForeColor.RGB = RGB(105, 205, 170)      ' 主力界入指數顯示之顏色    ---   藍綠色
                .ForeColor.RGB = RGB(32, 178, 170)         ' 主力界入指數顯示之顏色    ---   海洋綠色
                .Transparency = 0
                .Weight = 1                             '線條寬度
            End With
        End With

        With .SeriesCollection(6)
            .Name = "=data!$J$" & toindexRows
            .ChartType = xlLine
            With .Format.Line
                .Visible = msoTrue          ' 主力界入
                ' .ForeColor.RGB = RGB(105, 205, 170)      ' 主力界入指數顯示之顏色    ---   藍綠色
                .ForeColor.RGB = RGB(32, 178, 160)         ' 主力界入指數顯示之顏色    ---   海洋綠色
                .Transparency = 0
                .Weight = 1                             '線條寬度
            End With
        End With

        With .SeriesCollection(7)
            .Name = "=data!$J$" & toindexRows
            .ChartType = xlLine
            With .Format.Line
                .Visible = msoTrue          ' 主力界入
                ' .ForeColor.RGB = RGB(105, 205, 170)      ' 主力界入指數顯示之顏色    ---   藍綠色
                .ForeColor.RGB = RGB(32, 178, 150)         ' 主力界入指數顯示之顏色    ---   海洋綠色
                .Transparency = 0
                .Weight = 1                             '線條寬度
            End With
        End With

        With .SeriesCollection(8)
            .Name = "=data!$J$" & toindexRows
            .ChartType = xlLine
            With .Format.Line
                .Visible = msoTrue          ' 主力界入
                ' .ForeColor.RGB = RGB(105, 205, 170)      ' 主力界入指數顯示之顏色    ---   藍綠色
                .ForeColor.RGB = RGB(32, 178, 140)         ' 主力界入指數顯示之顏色    ---   海洋綠色
                .Transparency = 0
                .Weight = 1                             '線條寬度
            End With
        End With
                With .SeriesCollection(9)
            .Name = "=data!$J$" & toindexRows
            .ChartType = xlLine
            With .Format.Line
                .Visible = msoTrue          ' 主力界入
                ' .ForeColor.RGB = RGB(105, 205, 170)      ' 主力界入指數顯示之顏色    ---   藍綠色
                .ForeColor.RGB = RGB(32, 178, 130)         ' 主力界入指數顯示之顏色    ---   海洋綠色
                .Transparency = 0
                .Weight = 1                             '線條寬度
            End With
        End With

        With .SeriesCollection(10)
            .Name = "=data!$J$" & toindexRows
            .ChartType = xlLine
            With .Format.Line
                .Visible = msoTrue          ' 主力界入
                ' .ForeColor.RGB = RGB(105, 205, 170)      ' 主力界入指數顯示之顏色    ---   藍綠色
                .ForeColor.RGB = RGB(32, 178, 120)         ' 主力界入指數顯示之顏色    ---   海洋綠色
                .Transparency = 0
                .Weight = 1                             '線條寬度
            End With
        End With
                With .SeriesCollection(11)
            .Name = "=data!$J$" & toindexRows
            .ChartType = xlLine
            With .Format.Line
                .Visible = msoTrue          ' 主力界入
                ' .ForeColor.RGB = RGB(105, 205, 170)      ' 主力界入指數顯示之顏色    ---   藍綠色
                .ForeColor.RGB = RGB(32, 178, 110)         ' 主力界入指數顯示之顏色    ---   海洋綠色
                .Transparency = 0
                .Weight = 1                             '線條寬度
            End With
        End With

        With .SeriesCollection(12)
            .Name = "=data!$J$" & toindexRows
            .ChartType = xlLine
            With .Format.Line
                .Visible = msoTrue          ' 主力界入
                ' .ForeColor.RGB = RGB(105, 205, 170)      ' 主力界入指數顯示之顏色    ---   藍綠色
                .ForeColor.RGB = RGB(32, 178, 100)         ' 主力界入指數顯示之顏色    ---   海洋綠色
                .Transparency = 0
                .Weight = 1                             '線條寬度
            End With
        End With
                With .SeriesCollection(13)
            .Name = "=data!$J$" & toindexRows
            .ChartType = xlLine
            With .Format.Line
                .Visible = msoTrue          ' 主力界入
                ' .ForeColor.RGB = RGB(105, 205, 170)      ' 主力界入指數顯示之顏色    ---   藍綠色
                .ForeColor.RGB = RGB(32, 178, 180)         ' 主力界入指數顯示之顏色    ---   海洋綠色
                .Transparency = 0
                .Weight = 1                             '線條寬度
            End With
        End With
'        .Axes(xlValue).TickLabels.NumberFormatLocal = "0_ "
        
        With .Axes(xlCategory)                            ' X座標軸 (時間軸)
'            .CategoryType = xlCategoryScale
'            .TickLabels.NumberFormatLocal = "hh:mm"
'            .MajorTickMark = xlNone
'            .Border.Weight = xlHairline
'            .Border.LineStyle = xlNone
'            .TickLabelPosition = xlLow
'            .TickLabels.Font.Size = 10
         .MaximumScale = VIMax
         .MinimumScale = VIMin

        End With

'        .ChartArea.Height = cHeight * sRowHeight                           ' 將原本設定之高度調至適度位置
'        .ChartArea.Width = cWidth
'
'        text = "股票圖 K 線、主力、散戶、與成交量"
'
'        .SetElement (msoElementChartTitleCenteredOverlay)
'        .ChartTitle.text = text
'        .ChartTitle.Format.TextFrame2.TextRange.Font.Size = 14
'        .Legend.Position = xlCorner                         ' 將圖表圖示從圖表最下方調整到圖表之右上角位置
    End With

    chartname = Trim(Replace(ActiveChart.Name, ActiveSheet.Name, ""))
    ActiveSheet.Shapes(chartname).Left = Cells(xRow, yCol).Left     ' 設定此圖表實際擺放的 X、Y 座標位置。
    ActiveSheet.Shapes(chartname).Top = Cells(xRow, yCol).Top

    Range("A1").Select
'Debug.Print Sheets("data").Range("A" & Rows.Count).End(xlUp).Row
'Debug.Print Sheets("data").Range("I" & Rows.Count).End(xlUp).Row
Debug.Print toindexRows
End Sub

TOP

回復 6# wufonna
回復當事者時,請點按 "回復" 選鈕,否者當事人是無法得知
你是否答覆回應,這也是一種禮貌與尊重。
你的問題是否如圖?

TOP

回復 7# c_c_lai


謝謝 c_c_lai  大
昨天查了一晚,清楚了一些 VBA

還有問題請教大大

我把主線圖的
        .SeriesCollection(1).Name = ""    ' 開盤價
        .SeriesCollection(2).Name = ""    ' 最高價
        .SeriesCollection(3).Name = ""    ' 最低價
        .SeriesCollection(4).Name = ""    ' 收盤價 (成交價)
拿掉,前有一個空格(如圖),請問 大大可否調到中間來,謝謝

Mychart.GIF (50.29 KB)

Mychart.GIF

台灣加權指數-報酬率區間圖..rar (904.73 KB)

TOP

回復 8# wufonna
.HasLegend = 不是 True , 便是 False
試過的結果是無法將其中任一的 Legent 位置移開。

TOP

回復 9# c_c_lai


    謝謝 大大 我從中得到不少知識,
我研究好擷取歷史股價
再請教大大
^0^

TOP

        靜思自在 : 話多不如話少,話少不如話好。
返回列表 上一主題