I want to modify the Macro script to remove any negative value from my "Final" in the Excel file attached.

I want to modify the Macro script to remove any value from my "Final" in the Excel file attached.
SDGM.xlsm
Mohammed DallagPetroleum ConsultantAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
What do you want to replace on Final Worksheet and with what?
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
Please replace the existing code with the following codes and see if that works for you...
Sub MakeFinal()
    Dim wsWell As Worksheet, wsFinal As Worksheet
    Dim rwWellMax As Long, rwFinal As Long
    Dim col As Integer, colWellMax As Integer, colStep As Integer
    
    Application.ScreenUpdating = False
    Set wsWell = ThisWorkbook.Worksheets("SDGM (Static)")
    Set wsFinal = ThisWorkbook.Worksheets("Final")
    
    rwWellMax = wsWell.Range("A1").CurrentRegion.Rows.Count
    colWellMax = wsWell.Range("A1").CurrentRegion.Columns.Count
    colStep = wsWell.Range("B1").End(xlToRight).Column
    
    wsWell.Activate
    wsFinal.Cells.Clear
    'Headers
    wsWell.Range("A1").Copy wsFinal.Range("A1")
    wsWell.Range(wsWell.Cells(2, 1), wsWell.Cells(2, colStep - 1)).Copy wsFinal.Range("B1")
    colStep = colStep - 2
    
    'Copy data
    For col = 2 To colWellMax Step colStep
        rwFinal = wsFinal.Range("A1").CurrentRegion.Rows.Count + 1
        'Well
        wsFinal.Range("A" & rwFinal & ":A" & (rwWellMax - 3 + rwFinal)) = wsWell.Cells(1, col)
        'Dates
        wsWell.Range("A3:A" & rwWellMax).Copy wsFinal.Range("B" & rwFinal)
        'Data
        wsWell.Range(wsWell.Cells(3, col), wsWell.Cells(rwWellMax, col + colStep - 1)).Copy wsFinal.Range("C" & rwFinal)
    Next col
    
    wsFinal.Activate
    'Clear cells with No Data
    wsFinal.Cells.Replace What:="No Data", Replacement:="", LookAt:=xlWhole, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
    'Clear cells with Pt Created
    wsFinal.Cells.Replace What:="Pt Created", Replacement:="", LookAt:=xlWhole, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
    'Clear cells with Scan Timeout
    wsFinal.Cells.Replace What:="Scan Timeout", Replacement:="", LookAt:=xlWhole, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
     'Clear cells with I/O Timeout
    wsFinal.Cells.Replace What:="I/O Timeout", Replacement:="", LookAt:=xlWhole, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
    
    'Replace Negative Values
    ReplaceNegativeValues wsFinal
    'Adjust columns
    wsFinal.Columns.AutoFit
End Sub


'The following code replaces the negative values with blanks

Sub ReplaceNegativeValues(ws As Worksheet)
Dim x
Dim i As Long, j As Long
x = ws.Range("A1").CurrentRegion

For i = 1 To UBound(x, 1)
    For j = 1 To UBound(x, 2)
        If x(i, j) < 0 Then x(i, j) = ""     'If you want to replace negative values with 0, replace x(i, j) = "" with x(i, j) = 0 in this line
    Next j
Next i
ws.Range("A1").CurrentRegion.Value = x
End Sub

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
aikimarkCommented:
Do you want to use the absolute value of the cell values or clear the cell content?
Mohammed DallagPetroleum ConsultantAuthor Commented:
Thanks
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
You're welcome!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.