-2
我有兩個按鈕循環通過記錄(在這種情況下,僱員)。訪問:轉到下一個記錄創建空記錄
按鈕之一是上一個記錄它將瀏覽所有emoloyees,直到第一個emoloyee。到達第一名員工後,該按鈕將不會執行任何操作。
但是,對於*下一個記錄*按鈕,由於某種原因,在轉到最後一個可見僱傭後,再次按下它將轉到新的或**空白**記錄。
不知道如何解決該錯誤,
幫助非常感謝!
Sub WinLossSplit()
Dim ws As Worksheet
Application.DisplayAlerts = False
Application.ScreenUpdating = False
For Each ws In Worksheets
If ws.Name <> "Sheet1" And ws.Name <> "Sheet2" Then
If Application.WorksheetFunction.CountA(ws.Range("A:A")) > 0 Then
ws.Range("A:A").TextToColumns Destination:=ws.Range("A:B"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
Semicolon:=False, Comma:=True, Space:=False, Other:=True, OtherChar _
:=True, FieldInfo:=Array(Array(1, 1), Array(2, 1)), TrailingMinusNumbers:=True
End If
End If
Next ws
Application.DisplayAlerts = True
Application.ScreenUpdating = True
MsgBox ("done")
End Sub
Sub hello()
Dim a, i As Long, w(), k(), n As Long
Dim dic As Object, ws As Worksheet, s As String
For Each ws In Worksheets
dic.comparemode = vbTextCompare
'With Sheets("Sheet1")
a = ws.Range("a1:b" & ws.Range("a" & Rows.Count).End(xlUp).Row)
'End With
ReDim w(1 To UBound(a, 1), 1 To 2)
Set dic = CreateObject("scripting.dictionary")
For i = 1 To UBound(a, 1)
If Not IsEmpty(a(i, 1)) Then
' If Not dic.exists(a(i, 1)) Then
' n = n + 1
' w(n, 1) = a(i, 1): w(n, 2) = a(i, 2)
' dic.Add a(i, 1), Array(n, 2)
'Else
k = dic.Item(a(i, 1))
w(k(0), 2) = w(k(0), 2) & "," & a(i, 2)
dic.Item(a(i, 1)) = k
'End If
End If
Next
On Error Resume Next
'Set ws = Sheets("FinalReport")
On Error GoTo 0
If ws Is Nothing Then
' Set ws = Worksheets.Add: ws.Name = "FinalReport"
End If
With ws.Range("a1")
'.Resize(, 2).Value = Array("Array", "Datetime period")
.Resize(, 1).Value = Array("Array", "Datetime period")
For i = 1 To n
If Len(w(i, 2)) > 1024 Then
s = w(i, 2)
.Offset(i).Value = w(i, 1)
.Offset(i, 1).Value = s
Else
.Offset(i).Value = w(i, 1)
.Offset(i, 1).Value = w(i, 2)
End If
Next
' puts in separate columns rather than string with commas
.Offset(1, 1).Resize(n).TextToColumns _
Destination:=.Offset(1, 1), DataType:=xlDelimited, Comma:=True
End With
Set dic = Nothing: Erase a
Next ws
End Sub
謝謝,反正有沒有VBA做到這一點? I.E關於已經在Access中使用的宏表達式構建器(編碼塊)? – Urvil
我想這樣,但不能告訴。我不會做宏。 – Gustav
謝謝!只需將宏轉換爲vba並添加了您的代碼行即可使用。 – Urvil