컴퓨터/엑셀

vba 상태표시줄 구구단, 잠시멈춤, 숫자에서 소수점이하 없이 자연수부분만 CInt

풍경소리^^ 2023. 11. 16. 10:49
Sub StatusBarInfo_gugudan()
    Dim wb As Workbook
    Set wb = Application.ActiveWorkbook
    Dim lastLevel As Integer
    Dim col As Integer
    Dim per As Single
    Dim i As Integer, j As Integer, k As Integer
    
    Dim ws As Worksheet
    Set ws = wb.Worksheets("Sheet2")
    ws.Activate
    
    ' 시트 안 전체 지우기
    ActiveSheet.Cells.Clear
'    ActiveSheet.Range("A1").CurrentRegion.ClearContents
    
    ' 마지막 단
    lastLevel = 5
    col = lastLevel - 1
    k = 0
    For j = 1 To col '행
        For i = 1 To 9 '열
'            Cells(i, j).Value = Left(wb.Name, (InStrRev(wb.Name, ".", -1, vbTextCompare) - 1))
            Cells(i, j) = i * (j + 1) & "=" & j + 1 & "열×" & i & "행"
            
            k = k + 1
            per = k / (col * 9) * 100
            ' 나누어 떨어지는지 확인
            If CInt(per) = per Then
                 Application.StatusBar = "데이터 입력중.. " & Format(per, "0") & "% 완료"
'                 Application.Wait (Now + TimeValue("0:00:01"))
            Else
                Application.StatusBar = "데이터 입력중.. " & Format(per, "0.0") & "% 완료"
'            Application.Wait Now + TimeValue("00:00:01")
            End If

        Next i
    Next j
   
    Application.StatusBar = False
   
End Sub