VBA Abs - Absolute

Trying2learnVBA

Board Regular
Joined
Aug 21, 2019
Messages
67
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
Hello,

I am unable to figure out a way to convert a range to absolutes using VBA.

This is the code I am trying:

VBA Code:
Sub Convert_Range_to_Absolute()

End Sub

Dim Ws As Worksheet
Dim LastRow As Long
Dim iValue As Integer
Dim vResult As Variant
iValue = .Range("D:D" & LastRow)
vResult = Abs(iValue)

Set Ws = ActiveWorkbook.Sheets("Sheet1")

.Range("J:J" & LastRow).Value = vResult

End With

End Sub

Does anybody know of a method that works? Am I far off?

I would like to convert range D:D and last row to Abs.

Thank you!!!
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Try this (assumes your data starts in row 2 - let me know if it doesn't)

VBA Code:
Option Explicit
Sub Trying2learnVBA()
    Dim ws As Worksheet, lRow As Long
    Set ws = Worksheets("Sheet1")
    lRow = ws.Cells(Rows.Count, "D").End(xlUp).Row
    
    ws.Range("J2:J" & lRow).Value = ws.Evaluate("ABS(D2:D" & lRow & ")")

End Sub
 
Upvote 0
Solution
VBA Code:
Sub UseABS()
    Dim r$: r = Range("D2", Range("D" & Rows.Count).End(xlUp)).Address
    Range(r) = Evaluate("=abs(" & r & ")")
End Sub
 
Upvote 0
Try this (assumes your data starts in row 2 - let me know if it doesn't)

VBA Code:
Option Explicit
Sub Trying2learnVBA()
    Dim ws As Worksheet, lRow As Long
    Set ws = Worksheets("Sheet1")
    lRow = ws.Cells(Rows.Count, "D").End(xlUp).Row
   
    ws.Range("J2:J" & lRow).Value = ws.Evaluate("ABS(D2:D" & lRow & ")")

End Sub
This works. Thank you!
 
Upvote 0
VBA Code:
Sub UseABS()
    Dim r$: r = Range("D2", Range("D" & Rows.Count).End(xlUp)).Address
    Range(r) = Evaluate("=abs(" & r & ")")
End Sub
I tried this as well, this did not work for me. I am not clear as to how this code tells excel to put the result in column J.
 
Upvote 0
Is what you asked for.
Oh your code does work - it converted D:D to absolutes. Pretty cool. New trick for me. Now I'll play around with my report to see if I can use this method without the abs value going to col. J.
 
Upvote 0

Forum statistics

Threads
1,215,455
Messages
6,124,938
Members
449,197
Latest member
k_bs

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top