PDA

View Full Version : [SOLVED] excel macro help



joeny0706
11-29-2018, 11:09 AM
Hi All


I need to create visual basic command that I can use on an excel workbook. I need it to search all worksheets and make all negative numbers into positive numbers.
I did find one but it also made positive into negative. Cant have that.
and
Also another one I need is to fill a column saying "Passed" in each row based on another column with text. I am able to make ones that fill the column but then make the worksheet 60,000 rows or I need to pick a pre determined length.

Also at the same time to do on all the sheets.
I just started a new job. I have never worked with macros and visual basics. But I was asked to complete a task and since I am new I am trying to learn fast and get support from others
Maybe I should start a new thread but just asking you quick\\Again thanks for all the help

Paul_Hossler
11-29-2018, 12:46 PM
Most straight forward way

Code is fairly self explanatory, but online help is good

Ask any questions




Option Explicit
Sub NegToPos()
Dim ws As Worksheet
Dim r As Range, c As Range

Application.ScreenUpdating = False

For Each ws In ActiveWorkbook.Worksheets

Set r = Nothing

'in case there are no constant numbers
On Error Resume Next
Set r = ws.UsedRange.SpecialCells(xlCellTypeConstants, xlNumbers)
On Error GoTo 0

If Not r Is Nothing Then
For Each c In r.Cells
If c.Value < 0 Then c.Value = -1# * c.Value
Next
End If

Next

Application.ScreenUpdating = True
End Sub

macropod
12-09-2018, 05:18 PM
Cross-posted at: https://www.techsupportforum.com/forums/f57/macro-help-1233472.html

Please read VBA Express' policy on Cross-Posting in item 3 of the rules: http://www.vbaexpress.com/forum/faq.php?faq=new_faq_item#faq_new_faq_item3

joeny0706
12-09-2018, 09:26 PM
Thank Youˇˇ for All the help