Access交流中心

北京 | 上海 | 天津 | 重庆 | 广州 | 深圳 | 珠海 | 汕头 | 佛山 | 中山 | 东莞 | 南京 | 苏州 | 无锡 | 常州 | 南通 | 扬州 | 徐州 | 杭州 | 温州 | 宁波 | 台州 | 福州 | 厦门 | 泉州 | 龙岩 | 合肥 | 芜湖 | 成都 | 遂宁 | 长沙 | 株洲 | 湘潭 | 武汉 | 南昌 | 济南 | 青岛 | 烟台 | 潍坊 | 淄博 | 济宁 | 太原 | 郑州 | 石家庄 | 保定 | 唐山 | 西安 | 大连 | 沈阳 | 长春 | 昆明 | 兰州 | 哈尔滨 | 佳木斯 | 南宁 | 桂林 | 海口 | 贵阳 | 西宁 | 乌鲁木齐 | 包头 |

用VBA如何定位大中小

旺彩童子  发表于:2008-12-23 10:16:01  
复制

 

如何用VBA 将P3 游戏百十个的数定位成大中小组合?

A 列- 期号   (不断往下更新。。)

B 列- 百位数号码

c 列-十位号

d 列-个位号

E 列- 大中小形态的组合。。要求用VBA 写

0-2 号: 定义为小

3-6 号: 定义为中

7-9号: 定义为大

 

 

 

Top
小龙女 发表于:2008-12-23 14:28:34

可以一个一个数字进行判断,采用left函数,mid函数。

假定 值为: A159

则:

dim strValue as string

dim strMyValue as string

strValue="A159"

if val(mid(strValue,2,1))<3 then '百位数字

  strMyValue="小"

  else

   if val(mid(strValue,2,1))<7 then

     strMyValue="中"

     else

       strMyValue="大"

   end if

end if

 

if val(mid(strValue,3,1))<3 then '十位数字

  strMyValue=strMyValue & "小"

  else

   if val(mid(strValue,3,1))<7 then

     strMyValue=strMyValue & "中"

     else

       strMyValue=strMyValue & "大"

   end if

end if

 

if val(mid(strValue,4,1))<3 then '个位数字

  strMyValue=strMyValue & "小"

  else

   if val(mid(strValue,4,1))<7 then

     strMyValue=strMyValue & "中"

     else

       strMyValue=strMyValue & "大"

   end if

end if



旺彩童子 发表于:2008-12-23 16:08:12

老大。谢! 但还不是我想要的。原因有二

1: strValue 是在A 列的数组。可能有二〇〇〇个开奖号。 有二〇〇〇次的结果。

2: 大中小组合。也是在B列的数组。每期对应一个。。

 

可能你还要加上循环的语句。另判断好像过于沉重了。。

 

我是VBA 新蔡鸟。。知道个大概。拜托老大在发发功力。。 谢谢

 

A      B

A123  xiao xiao xiao

A519  zhong xiao da

A678  zhong zhong Da

....    ......

 



旺彩童子 发表于:2008-12-25 14:24:17

在小龙女的帮助下 和本人的努力下。。。呵呵 搞定。。 谢谢小龙女!!!

 

Public Sub 大中小()

Dim strValue As String
Dim strMyValue As String
Dim myRange As Range

For Each myRange In Range("A1:A200")
    strValue = myRange.Value
        If Val(Left(strValue, 1)) < 3 Then '百位数字
            strMyValue = "小"
              myRange.Offset(0, 1).Value = strMyValue
             Else

         If Val(Left(strValue, 1)) < 7 Then
             strMyValue = "中"
                myRange.Offset(0, 1).Value = strMyValue
             Else
      
             strMyValue = "大"
                myRange.Offset(0, 1).Value = strMyValue
              End If
     
    End If
      
        If Val(Mid(strValue, 2, 1)) < 3 Then '十位数字
             strMyValue = strMyValue & "小"
             myRange.Offset(0, 1).Value = strMyValue
             Else
   
                 If Val(Mid(strValue, 2, 1)) < 7 Then
                      strMyValue = strMyValue & "中"
                       myRange.Offset(0, 1).Value = strMyValue
              Else
      
                      strMyValue = strMyValue & "大"
                          myRange.Offset(0, 1).Value = strMyValue
     End If
     
       End If
      
      If Val(Right(strValue, 1)) < 3 Then '个位数字
             strMyValue = strMyValue & "小"
             myRange.Offset(0, 1).Value = strMyValue
             Else
   
                 If Val(Right(strValue, 1)) < 7 Then
                      strMyValue = strMyValue & "中"
                       myRange.Offset(0, 1).Value = strMyValue
              Else
      
                      strMyValue = strMyValue & "大"
                          myRange.Offset(0, 1).Value = strMyValue
     End If
     
       End If
       
       Next
      
   End Sub



总记录:3篇  页次:1/1 9 1 :