之前的改写

Sub check_output()
Dim row As Integer, c As IntegerDim arr(1 To 100), arr1(1 To 100)Dim regDim wb As WorkbookIf Range(“c1”) <> “使用” Then MsgBox “C1单元格未选择使用!” Exit SubEnd Ifrow = Range(“A1”).CurrentRegion.Rows.Countreg = ActiveSheet.UsedRangeFor i = LBound(reg) + 3 To UBound(reg) For j = 2 To UBound(reg, 2) If reg(i, j) <> “” Then If j < 3 Then If Len(reg(i, j)) <> 4 Then MsgBox GetColName(j) & i & “单元格内容长度不为4!” Exit Sub End If Else If Len(reg(i, j)) <> 2 Then MsgBox GetColName(j) & i & “单元格内容长度不为2!” Exit Sub End If End If End If NextNextFor i = LBound(reg) + 3 To UBound(reg) rn = 0 mzchongfu = “” rn = Application.WorksheetFunction.CountIfs(Range(Cells(i, “b”), Cells(row, “b”)), Cells(i, “b”)) If rn > 1 Then mzchongfu = “B” & i For ii = i + 1 To UBound(reg) If reg(ii, 2) = Cells(i, “b”) Then mzchongfu = mzchongfu & “/” & “B” & ii End If Next MsgBox mzchongfu & “单元格内容重复!” Exit Sub End If For j = 3 To UBound(reg, 2) cn = 0 ywchongfu = “” cn = Application.WorksheetFunction.CountIfs(Range(Cells(i, “c”), Cells(i, UBound(reg, 2))), reg(i, j)) If cn > 1 Then ywchongfu = GetColName(j) & i For jj = j + 1 To UBound(reg, 2) If reg(i, jj) = reg(i, j) Then ywchongfu = ywchongfu & “/” & GetColName(jj) & i End If Next MsgBox ywchongfu & “单元格内容重复!” Exit Sub End If NextNextApplication.ScreenUpdating = FalseSet wb = Workbooks.Addt = 1For i = LBound(reg) + 3 To UBound(reg) For j = 3 To UBound(reg, 2) If reg(i, j) <> “” Then wb.Sheets(1).Cells(t, “a”) = “#thisis 行(” & i & “)列(” & GetColName(j) & “)” wb.Sheets(1).Cells(t + 1, “a”) = reg(1, 5) & " " & reg(i, 2) & reg(i, j) & “=” & reg(1, 7) wb.Sheets(1).Cells(t + 2, “a”) = reg(1, 5) & " " & reg(i, 2) & reg(i, j) t = t + 4 End If NextNextwb.SaveAs ThisWorkbook.Path & “\输出结果” & Format(Now, “yyyymmddhhmmss”) & “.txt”, FileFormat:=xlText, CreateBackup:=Falsewb.Close FalseApplication.ScreenUpdating = True End SubFunction GetColName(ByVal y As Integer) As StringDim z As IntegerDim i As IntegerDim n(25) As StringFor i = 0 To 25 n(i) = Chr(65 + i)NextIf y <= 26 Then GetColName = n(y - 1) Exit FunctionEnd Ifz = y \ 26If y Mod 26 = 0 Then GetColName = n(z - 2)Else GetColName = n(z - 1)End Ifz = y Mod 26If z > 0 Then GetColName = GetColName & n(z - 1)Else GetColName = GetColName & "Z"End If End Function

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值