NumberFormat is not formatting correctly

ExcelEndeavor

New Member
Joined
Oct 13, 2020
Messages
49
Office Version
  1. 365
Platform
  1. MacOS
When clicking a command button in a userform, I am sending data to a worksheet ("PO Data"). This code uses a NumberFormat command with accounting format, but when I check the worksheet, it is still in currency format. I have column (G) in the worksheet formatted for accounting as well, so not sure why this is not formatted accurately. I use the same code on another userform that sends to a different worksheet and it works flawlessly. The accounting format line is towards the bottom. What might prevent the NumberFormat from formatting correctly in this instance?


VBA Code:
Private Sub ButtonAddInvoice_Click()
 
    'Declare worksheet variable
    Dim rSh As Worksheet
    On Error Resume Next
    Set rSh = ThisWorkbook.Sheets("PO Data")
    On Error GoTo 0
  
        'If it is a new record
    'Get the next available row
    Dim nextRow As Long
    If Label2 = "True" Then
      nextRow = updateRow
  
    MsgBox "Successfully Added"
    Unload Me
 
    Else
      nextRow = rSh.Range("A" & Rows.Count).End(xlUp).Row + 1
    End If
  
    'Assign columns
    rSh.Range("A" & nextRow).Value = RequestForm.TxtTeamLead
    rSh.Range("B" & nextRow).Value = RequestForm.ComboBU
    rSh.Range("C" & nextRow).Value = RequestForm.TxtPayee
    rSh.Range("D" & nextRow).Value = RequestForm.TxtPONbr
    rSh.Range("E" & nextRow).Value = TxtInvoiceNumber
    rSh.Range("F" & nextRow).Value = TxtInvoiceDate
    rSh.Range("G" & nextRow).Value = TxtInvoiceAmount
    rSh.Range("H" & nextRow).Value = CheckboxPaidInvoice
      
        'Change the CheckboxPaidInvoice output to "Paid" or ""
        If Me.CheckboxPaidInvoice.Value = True Then
            rSh.Range("H" & nextRow).Value = "Paid"
        Else
            rSh.Range("H" & nextRow).Value = ""
        End If
 
    ' Activate the UpdateInvoiceList subroutine in the RequestForm userform
    Call RequestForm.UpdateInvoiceList
 
    'Format currency to accounting in worksheet
    rSh.Range("G:G").NumberFormat = "_($* #,##0.00_);_($* (#,##0.00);_($* ""-""??_);_(@_)"
 
    'Unload Me
    clearForm
    Unload Me
 
End Sub


Thank you in advance.
 
That didn't work - when the data is sent from the userform to the worksheet, it reverts back to

2025-03-13_10-32-00.jpg


and the green triangle says "Number Stored as Text"
 
Upvote 0
If you used CDbl as suggested that could not happen
 
Upvote 0
Thank you MARK858 - changing the code to CDbl did the trick. You are correct that I didn't see that part initially. Thank you again for solving that for me.
 
Upvote 0

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