ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

½Ð°Ý«ç¼Ë°µ¥X¨Ó

½Ð°Ý«ç¼Ë°µ¥X¨Ó

¥»©«³Ì«á¥Ñ cdkee ©ó 2010-9-29 06:20 ½s¿è

¥H¥t¤@¤è­±·Q¡A¥ÎEXCEL «ç¼Ë¥i¥H­pºâ¥X¨C¹ï¶R½æÁÈ»k¼Æ¥Ø¡A©ñ¤JC¨º¦æ?( )¤ºªº¼Æ­È¬O§Ú¦Û¤v­pºâ¥X¨Ó¡CÁÂÁ¤j¤j!
¨C­Ó¶R½æ¼Æ¶q=1
¶R=¶R¤J, ½æ=ªfªÅ(§Y¥­¤F¶R¤J¡AµL³f®É¡AªfªÅ´N¬O¬Ý¶^)

A  B=¶R½æ»ù C
¶R 8
¶R 6
½æ 6       (-2)
½æ 3       (-3)
½æ 4
½æ 8
¶R 1       (3)
¶R 8       (0)
¶R 9
½æ 8       (-1)
¶R 1
¶R 5
½æ 9      (8)
¶R 8
½æ 4      (-1)
½æ 10     (2)
¶R 9
½æ 1      (-8)

²Ä¤@¦C¬°Äæ¦W
  1. Sub Buy_Sale()
  2. Dim Sale, Buy, A As Range, s&, k&
  3. Set Sale = CreateObject("Scripting.Dictionary")
  4. Set Buy = CreateObject("Scripting.Dictionary")
  5. For Each A In Range([A2], [A65536].End(xlUp))
  6.    Select Case A.Value
  7.       Case "¶R"
  8.       If Sale.Count > 0 Then
  9.       A.Offset(, 2) = Sale(s) - A.Offset(, 1)
  10.       Sale.Remove s
  11.       s = s + 1
  12.       Else
  13.       Buy(s) = A.Offset(, 1)
  14.       A.Offset(, 2) = ""
  15.       s = s + 1
  16.       End If
  17.       Case "½æ"
  18.       If Buy.Count > 0 Then
  19.       A.Offset(, 2).Value = A.Offset(, 1) - Buy(k)
  20.       Buy.Remove k
  21.       k = k + 1
  22.       Else
  23.       Sale(k) = A.Offset(, 1)
  24.       A.Offset(, 2) = ""
  25.       k = k + 1
  26.       End If
  27.    End Select
  28. Next
  29. End Sub
½Æ»s¥N½X
·l¯q.rar (8.31 KB)
¾Ç®üµL²P_¤£®¢¤U°Ý

TOP

¦^´_ 2# Hsieh


    ÁÂÁª©¤j±Ð¾É!
1)¸òª©¤jªºµ{¦¡¡Aµ²ªG¦p¤U¡A¦ý­pºâªºµ²ªG¥u¦³8­Ó¡AÀ³¸Ó¦³9­Ó(¬A©·ªº¬O·Q­nªºµ²ªG¡A¬O¥Hfirst in first out¤è¦¡­pºâ)
2)¦p¦ó¤~°µ¨ì¦b¿é¤J¶R½æ®É¡A§Y®É­pºâµ²ªG¡C

¶R        8       
¶R        6       
½æ        6        0(-2)
½æ        3                 (-3)       
½æ        4       
½æ        8       
¶R        1        2(3)
¶R        8        -4(0)
¶R        9        -1
½æ        8                  (-1)       
¶R        1        7
¶R        5       
½æ        9        4(8)
¶R        8       
½æ        4        -4(-1)
½æ        10            (2)
¶R        9        1
½æ        1             (-8)

TOP

¦^´_ 2# Hsieh


    ¦A½Ð±Ðª©¤j¡A¥H¤U¬O¤p½úªºµ{¦¡¡A«ç¼Ë¥[¤Jª©¤jªºµ{¦¡¦b¦Û¤vªºµ{¦¡¤¤¤~¹ï?ÁÂÁÂ!
Public i As Integer
Public m As Integer
Public n As Integer
Public B As Integer
Public S As Integer
Public check As Integer
Dim buyArray(99) As Single
Dim sellArray(99) As Single
Private Sub CommandButton1_Click()

B = 1
i = i + 1
        Sheets("sheet1").Cells(i, 1) = "¶R"
        Sheets("sheet1").Cells(i, 2) = Int((10 * Rnd) + 1)
        
m = m + 1
buyArray(m) = Sheets("sheet1").Cells(i, 2)


End Sub
Private Sub CommandButton2_Click()

S = 1
i = i + 1
        Sheets("sheet1").Cells(i, 1) = "½æ"
        Sheets("sheet1").Cells(i, 2) = Int((10 * Rnd) + 1)
        
n = n + 1
sellArray(n) = Sheets("sheet1").Cells(i, 2)


End Sub

TOP

¥»©«³Ì«á¥Ñ Hsieh ©ó 2010-9-29 22:33 ½s¿è
  1. Private Sub CommandButton1_Click()
  2. r = Application.CountA(Columns("A")) + 1
  3.         Sheets("sheet1").Cells(r, 1) = "¶R"
  4.         Randomize
  5.         Sheets("sheet1").Cells(r, 2) = Int((10 * Rnd) + 1)
  6. Buy_Sale
  7. End Sub
  8. Private Sub CommandButton2_Click()

  9. r = Application.CountA(Columns("A")) + 1
  10.         Sheets("sheet1").Cells(r, 1) = "½æ"
  11.         Randomize
  12.         Sheets("sheet1").Cells(r, 2) = Int((10 * Rnd) + 1)
  13. Buy_Sale
  14. End Sub
  15. Sub Buy_Sale()
  16. Dim Sale, Buy, A As Range, s&, k&
  17. Set Sale = CreateObject("Scripting.Dictionary")
  18. Set Buy = CreateObject("Scripting.Dictionary")
  19. For Each A In Range([A1], [A65536].End(xlUp))
  20.    Select Case A.Value
  21.       Case "¶R"
  22.       If Sale.Count > 0 Then
  23.       A.Offset(, 2) = Sale(s) - A.Offset(, 1)
  24.       Sale.Remove s
  25.       s = s + 1
  26.       Else
  27.       Buy(s) = A.Offset(, 1)
  28.       A.Offset(, 2) = ""
  29.       s = s + 1
  30.       End If
  31.       Case "½æ"
  32.       If Buy.Count > 0 Then
  33.       A.Offset(, 2).Value = A.Offset(, 1) - Buy(k)
  34.       Buy.Remove k
  35.       k = k + 1
  36.       Else
  37.       Sale(k) = A.Offset(, 1)
  38.       A.Offset(, 2) = ""
  39.       k = k + 1
  40.       End If
  41.    End Select
  42. Next
  43. End Sub
½Æ»s¥N½X
¾Ç®üµL²P_¤£®¢¤U°Ý

TOP

¦^´_ 5# Hsieh


    ²\¦p«B¤U ¡A¤p½ú·P¿EµL¨¥!¦A²Ó¨ýª©¤j¬ü·N!

TOP

        ÀR«ä¦Û¦b : §Ñ¥\¤£§Ñ¹L¡A§Ñ«è¤£§Ñ®¦¡C
ªð¦^¦Cªí ¤W¤@¥DÃD