Przemek Dabek
Przemek Dabek

Reputation: 533

VBA Convert Negative Numbers to Postive

after the function that filters my results below zero, I have to write it as a positive result, i.e. without "-". However, I get the error "Object variable or With block not set" . What I doing wrong ?

Dim cl As Range
cl = wbMe.Sheets("pochodne").Range("T35").Copy
   If cl.Value < 0 Then
       cl.Value = -cl.Value
   End If

Upvotes: 3

Views: 2993

Answers (1)

Gustav
Gustav

Reputation: 56026

Objects need to be "set", so try:

Dim wbMe    As Excel.Workbook
Dim cl      As Excel.Range

Set wbMe = ThisWorkbook

Set cl = wbMe.Worksheets("pochodne").Range("T35")
If cl.Value < 0 Then
   cl.Value = -cl.Value
End If

That works here.

Upvotes: 4

Related Questions