![]() |
Question about VarType
With the following macro if a cell has a value of 5 in it, the macro
identifies it as a double, I would have expected it to come back as an integer. Can you tell me what I'm doing incorrectly? tia Sub DisplayCellDataAttributes() If Not RangeTools.IsRangeValid Then Exit Sub Application.ScreenUpdating = False For Each rngCell In Selection If (VarType(rngCell.Cells) = vbInteger) Then MsgBox rngCell.Address & vbCrLf & vbCrLf & " Cell DATA Format - Integer" & vbCrLf & vbCrLf & "Data: " & rngCell.Cells & vbCrLf & vbCrLf & "VarType: " & VarType(rngCell.Cells) If (VarType(rngCell.Cells) = vbLong) Then MsgBox rngCell.Address & vbCrLf & vbCrLf & " Cell DATA Format - Long" & vbCrLf & vbCrLf & "Data: " & rngCell.Cells & vbCrLf & vbCrLf & "VarType: " & VarType(rngCell.Cells) If (VarType(rngCell.Cells) = vbDouble) Then MsgBox rngCell.Address & vbCrLf & vbCrLf & " Cell DATA Format - Double" & vbCrLf & vbCrLf & "Data: " & rngCell.Cells & vbCrLf & vbCrLf & "VarType: " & VarType(rngCell.Cells) Next Application.ScreenUpdating = True End Sub |
Question about VarType
Hi Bill,
You should use IF-ELSEIF-END. Please try the following one. Sub DisplayCellDataAttributes() Application.ScreenUpdating = False For Each rngCell In Selection If (VarType(rngCell.Cells) = vbInteger) Then MsgBox rngCell.Address & vbCrLf & vbCrLf & " Cell DATA Format - Integer" _ & vbCrLf & vbCrLf & "Data: " & rngCell.Cells & vbCrLf & vbCrLf _ & "VarType: " & VarType(rngCell.Cells) ElseIf (VarType(rngCell.Cells) = vbLong) Then MsgBox rngCell.Address & vbCrLf & vbCrLf & " Cell DATA Format - Long" _ & vbCrLf & vbCrLf & "Data: " & rngCell.Cells & vbCrLf & vbCrLf _ & "VarType: " & VarType(rngCell.Cells) ElseIf (VarType(rngCell.Cells) = vbDouble) Then MsgBox rngCell.Address & vbCrLf & vbCrLf & " Cell DATA Format - Double" _ & vbCrLf & vbCrLf & "Data: " & rngCell.Cells & vbCrLf & vbCrLf _ & "VarType: " & VarType(rngCell.Cells) End If Next Application.ScreenUpdating = True End Sub Best Regards Bill -----Original Message----- With the following macro if a cell has a value of 5 in it, the macro identifies it as a double, I would have expected it to come back as an integer. Can you tell me what I'm doing incorrectly? tia Sub DisplayCellDataAttributes() If Not RangeTools.IsRangeValid Then Exit Sub Application.ScreenUpdating = False For Each rngCell In Selection If (VarType(rngCell.Cells) = vbInteger) Then MsgBox rngCell.Address & vbCrLf & vbCrLf & " Cell DATA Format - Integer" & vbCrLf & vbCrLf & "Data: " & rngCell.Cells & vbCrLf & vbCrLf & "VarType: " & VarType(rngCell.Cells) If (VarType(rngCell.Cells) = vbLong) Then MsgBox rngCell.Address & vbCrLf & vbCrLf & " Cell DATA Format - Long" & vbCrLf & vbCrLf & "Data: " & rngCell.Cells & vbCrLf & vbCrLf & "VarType: " & VarType(rngCell.Cells) If (VarType(rngCell.Cells) = vbDouble) Then MsgBox rngCell.Address & vbCrLf & vbCrLf & " Cell DATA Format - Double" & vbCrLf & vbCrLf & "Data: " & rngCell.Cells & vbCrLf & vbCrLf & "VarType: " & VarType(rngCell.Cells) Next Application.ScreenUpdating = True End Sub . |
All times are GMT +1. The time now is 03:02 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com