|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
香川群子 发表于 2013-1-30 09:34
VBA简单代码时,使用a、b、c、d单字母变量是一个很好的习惯。
非常简明。
刚好有人发了求助贴了,楼主帮忙给人改改代码吧 http://club.excelhome.net/thread-978527-1-1.html
{:soso_e120:}
Worksheets(2).[A1].CurrentRegion.ClearContents
Ca = WorksheetFunction.CountA(Range("A2:A12"))
Cb = WorksheetFunction.CountA(Range("B2:B12"))
Cc = WorksheetFunction.CountA(Range("C2:C12"))
Cd = WorksheetFunction.CountA(Range("D2:D12"))
Ce = WorksheetFunction.CountA(Range("E2:E12"))
Cf = WorksheetFunction.CountA(Range("F2:F12"))
Cg = WorksheetFunction.CountA(Range("G2:G12"))
If Ca = 0 Then Ca = 1
If Cb = 0 Then Cb = 1
If Cc = 0 Then Cc = 1
If Cd = 0 Then Cd = 1
If Ce = 0 Then Ce = 1
If Cf = 0 Then Cf = 1
If Cg = 0 Then Cg = 1
R = 1
Col = 1
For Ra = 2 To Ca + 1
If Cells(Ra, 1) = "" Then
a = ""
Pa = ""
Na = 0
Else
a = Cells(Ra, 1)
Pa = a Mod 2
Na = Val(a)
End If
For Rb = 2 To Cb + 1
If Cells(Rb, 2) = "" Then
b = ""
Pb = ""
Nb = 0
Else
b = Cells(Rb, 2)
Pb = b Mod 2
Nb = Val(b)
End If
For Rc = 2 To Cc + 1
If Cells(Rc, 3) = "" Then
c = ""
Pc = ""
Nc = 0
c = Cells(Rc, 3)
Pc = c Mod 2
Nc = Val(c)
End If
For Rd = 2 To Cd + 1
If Cells(Rd, 4) = "" Then
d = ""
Pd = ""
Nd = 0
Else
d = Cells(Rd, 4)
Pd = d Mod 2
Nd = Val(d)
End If
For Re = 2 To Ce + 1
If Cells(Re, 5) = "" Then
e = ""
Pe = ""
Ne = 0
Else
e = Cells(Re, 5)
Pe = e Mod 2
Ne = Val(e)
End If
For Rf = 2 To Cf + 1
If Cells(Rf, 6) = "" Then
f = ""
Pf = ""
Else
f = Cells(Rf, 6)
Pf = f Mod 2
Nf = Val(f)
End If
For Rg = 2 To Cg + 1
If Cells(Rg, 7) = "" Then
g = ""
Pg = ""
Ng = 0
Else
g = Cells(Rg, 7)
Pg = g Mod 2
Ng = Val(g)
End If
Do While Worksheets(2).Cells(R, Col) <> ""
Col = Col + 1
If Col = 101 Then
R = R + 1
Col = 1
End If
Loop
Worksheets(2).Cells(R, Col) = a & b & c & d & e & f & g
Next Rg
Next Rf
Next Re
Next Rd
Next Rc
Next Rb
Next Ra |
|