Philip1957
Board Regular
- Joined
- Sep 30, 2014
- Messages
- 182
- Office Version
- 365
- Platform
- Windows
Greetings,
I have code that converts a range of numbers from negative to positive.
I'm trying to apply this to a Table and can't seem to get the syntax right. I've not used VBA with tables before. I've tried many variations of the following with no luck
Any assistance would be most appreciated.
Thank you,
~ Phil
I have code that converts a range of numbers from negative to positive.
VBA Code:
Sub negative_positive()
Dim conv As Range
'convert negative numbers to positive in the selection
For Each conv In Selection
If conv.Value < 0 Then
conv.Value = -conv.Value
ElseIf conv.Value > 0 Then
conv.Value = "0"
End If
Next conv
End Sub
I'm trying to apply this to a Table and can't seem to get the syntax right. I've not used VBA with tables before. I've tried many variations of the following with no luck
VBA Code:
Sub Neg2Pos()
Dim vList As ListObject
Dim vRow As ListRow
Dim vCol As ListColumn
Worksheets("Volume Data").Activate
Set vList = ActiveSheet.ListObjects("TblVolData")
Set vCol = ActiveSheet.ListObjects("TblVolData").ListColumns("Qty")
For Each vRow In vList
If vCol.Value < 0 Then
vCol.Value = -vCol.Value
ElseIf vCol.Value > 0 Then
vCol.Value = "0"
End If
Next vRow
End Sub 'Neg2Pos
Any assistance would be most appreciated.
Thank you,
~ Phil