3月 20, 2013

VBA 最後一欄

Dim uyt As Integer
uyt = Range("f65536").End(xlUp).Row + 1
WorkSheets("Sheet1").Cells(uyt,"F").Value = "hi"

在最後一欄補上文字

VBA

Sub Click()
    Worksheets("Sheet1").Range("A1").Value = Replace(Worksheets("Sheet2").Range("A1").Value, "年", "")
    Worksheets("Sheet1").Range("B1").Value = Replace(Worksheets("Sheet2").Range("B1").Value, "月", "")
    Worksheets("Sheet1").Range("C1").Value = Replace(Worksheets("Sheet2").Range("A12").Value, "日", "")
    Dim y, m, d, tq, ty As String
    y = Replace(Worksheets("Sheet2").Range("A1").Value, "年", "")
    m = Replace(Worksheets("Sheet2").Range("B1").Value, "月", "")
    If Len(m) = 1 Then
        m = "0" & m
    End If
    d = Replace(Worksheets("Sheet2").Range("A12").Value, "日", "")
    If Len(d) = 1 Then
        d = "0" & d
    End If
    tq = y & m & d
    ty = y & m
    '抓位補風
    Worksheets("Sheet1").Range("D1").Value = Split(Worksheets("Sheet2").Range("C2:AF2").Find(Worksheets("Sheet1").Range("C1").Value).Address(1, 0), "$")
    Dim aa As String
    aa = Worksheets("Sheet1").Range("D1").Value
    Dim j As Integer
    j = 1
    '找莊家號碼列欄
    For i = 3 To Worksheets("Sheet2").Range("A14").Value
        
        With Worksheets("Sheet2")
        If Not .Cells(i, aa).Value = "" Then
            
            Worksheets("Sheet1").Cells(j, 6).Value = .Cells(i, 1).Value & vbCrLf & .Cells(i, 2).Value
            Dim fg As String
            fg = .Cells(i, 2 + d).Value
            '爪爪
            If Not fg = "" Then
                For k = 1 To 7
                If .Cells(i, 2 + d + k).Value = "" Then
                    Dim re As String
                    re = d + k - 1
                    If Len(re) = 1 Then
                        re = "0" & re
                    End If
                    If fg = "8" Then
                    Worksheets("Sheet1").Cells(j, 7).Value = tq & "0800" & "-" & ty & re & Replace(.Cells(i, 2 + d + k - 1).Value, "例", "") & "00"
                    ElseIf fg = "18" Then
                    Worksheets("Sheet1").Cells(j, 7).Value = tq & "1800" & "-" & ty & re & Replace(.Cells(i, 2 + d + k - 1).Value, "例", "") & "00"
                    ElseIf fg = "例" Or fg = "慰" Or fg = "例21" Then
                        For g = 1 To 7
                        
                            
                                If Worksheets("Sheet2").Cells(2, 2 + d - g).Value = 1 And Not Worksheets("Sheet2").Cells(i, 2 + d - g).Value = "" Then
                                Worksheets("Sheet1").Cells(j, 7).Value = ty & "01" & .Cells(i, 2 + d - g).Value & "00" & "-" & ty & re & Replace(.Cells(i, 2 + d + k - 1).Value, "例", "") & "00"
                                Exit For
                                ElseIf .Cells(i, 2 + d - g).Value = "" Then
                                Dim ret As String
                                ret = d - g + 1
                                If Len(ret) = 1 Then
                                ret = "0" & ret
                                
                                Worksheets("Sheet1").Cells(j, 7).Value = ty & ret & .Cells(i, 2 + d - g + 1).Value & "00" & "-" & ty & re & Replace(.Cells(i, 2 + d + k - 1).Value, "例", "") & "00"
                                End If
                                
                                Exit For
                                End If
                                
                                
                                
                                
                            
                            
                        Next
                        
                    End If
                    
                    
                Exit For
                End If
                
                
                Next
                
                
            End If
            
            
            
            j = j + 1
            
            
        End If
        End With
    Next
    
    
    
    
End Sub