0% found this document useful (0 votes)
4 views1 page

Flipkart

The VBA macro 'ConvertValues' processes data in the 'Sales Report' worksheet by formatting numeric values in specific columns (N, Y, AG, AI, AK, AU) to two decimal places. It checks the value in column H; if it is 'RETURN', it makes the corresponding values negative, and if it is 'CANCELLED', it sets them to zero. The macro loops through each row starting from the second row, assuming the first row contains headers.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views1 page

Flipkart

The VBA macro 'ConvertValues' processes data in the 'Sales Report' worksheet by formatting numeric values in specific columns (N, Y, AG, AI, AK, AU) to two decimal places. It checks the value in column H; if it is 'RETURN', it makes the corresponding values negative, and if it is 'CANCELLED', it sets them to zero. The macro loops through each row starting from the second row, assuming the first row contains headers.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

Sub ConvertValues()

Dim ws As Worksheet
Dim lastRow As Long
Dim i As Long

' Set the worksheet


Set ws = ThisWorkbook.Sheets("Sales Report") ' Replace "Sheet1" with your
actual sheet name

' Find the last row with data in column N


lastRow = ws.Cells(ws.Rows.Count, "N").End(xlUp).Row

' Loop through each row


For i = 2 To lastRow ' Assuming row 1 is header

' Check if columns N, Y, AG, AI, AK, and AU have numeric values
If IsNumeric(ws.Cells(i, "N").Value) And IsNumeric(ws.Cells(i, "Y").Value)
And _
IsNumeric(ws.Cells(i, "AG").Value) And IsNumeric(ws.Cells(i,
"AI").Value) And _
IsNumeric(ws.Cells(i, "AK").Value) And IsNumeric(ws.Cells(i,
"AU").Value) Then

' Convert to number with 2 decimal places


ws.Cells(i, "N").Value = Format(CDbl(ws.Cells(i, "N").Value), "0.00")
ws.Cells(i, "Y").Value = Format(CDbl(ws.Cells(i, "Y").Value), "0.00")
ws.Cells(i, "AG").Value = Format(CDbl(ws.Cells(i, "AG").Value), "0.00")
ws.Cells(i, "AI").Value = Format(CDbl(ws.Cells(i, "AI").Value), "0.00")
ws.Cells(i, "AK").Value = Format(CDbl(ws.Cells(i, "AK").Value), "0.00")
ws.Cells(i, "AU").Value = Format(CDbl(ws.Cells(i, "AU").Value), "0.00")

' Check column H value


If UCase(ws.Cells(i, "H").Value) = "RETURN" Then
' If RETURN, make values negative
ws.Cells(i, "N").Value = -Abs(ws.Cells(i, "N").Value)
ws.Cells(i, "Y").Value = -Abs(ws.Cells(i, "Y").Value)
ws.Cells(i, "AG").Value = -Abs(ws.Cells(i, "AG").Value)
ws.Cells(i, "AI").Value = -Abs(ws.Cells(i, "AI").Value)
ws.Cells(i, "AK").Value = -Abs(ws.Cells(i, "AK").Value)
ws.Cells(i, "AU").Value = -Abs(ws.Cells(i, "AU").Value)
ElseIf UCase(ws.Cells(i, "H").Value) = "CANCELLED" Then
' If CANCELLED, set values to 0
ws.Cells(i, "N").Value = 0
ws.Cells(i, "Y").Value = 0
ws.Cells(i, "AG").Value = 0
ws.Cells(i, "AI").Value = 0
ws.Cells(i, "AK").Value = 0
ws.Cells(i, "AU").Value = 0
End If
End If
Next i
End Sub

You might also like