Share via

VBA Formatting - Userform

Anonymous
2018-07-09T16:04:40+00:00

Greetings!

I have a user form I am trying to format the output.

With wsInput

        .Columns("A:A").NumberFormat = "General"

        .Columns("B:B").NumberFormat = "mm/dd/yy;@"

        .Columns("E:E").NumberFormat = "mm/dd/yy;@"

        .Columns("J:J").NumberFormat = "$##,##0.00"

        .Columns("K:K").NumberFormat = "$##,##0.00"

        .Columns("C:C").NumberFormat = "0.00"

        .Columns("D:D").NumberFormat = "0.00"

        .Columns("F:F").NumberFormat = "0.00"

        .Columns("G:G").NumberFormat = "0.00"

        .Cells(lngRow, "A") = txtFIN

        .Cells(lngRow, "B") = txtDate

        .Cells(lngRow, "C") = txtDRG1

        .Cells(lngRow, "D") = txtDRG2

        .Cells(lngRow, "E") = txtDCDate

        .Cells(lngRow, "F") = txtW1

        .Cells(lngRow, "G") = txtW2

        .Cells(lngRow, "H") = txtCase

        .Cells(lngRow, "I") = txtCom

        .Cells(lngRow, "J") = txtCost1

        .Cells(lngRow, "K") = txtCost2

I'm not sure what I'm doing wrong.

When I fill in the user form, the numbers are still not formatted.  The data is populating a table, and I have to continually go in and format the numbers in the table.

Can anyone suggest a better way?

Can you tell me what I'm missing here?

Thank you so much!

jules

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

  1. Andreas Killer 144.1K Reputation points Volunteer Moderator
    2018-07-09T19:35:54+00:00

    All controls on your userform contains text, but the cells needs real values.
    Therefore you have to convert the text using e.g. CDate for date strings.

    Make a new file and try this
    Range("A1") = CDate("12/24/2018")

    Andreas.

    1 person found this answer helpful.
    0 comments No comments

7 additional answers

Sort by: Most helpful
  1. Andreas Killer 144.1K Reputation points Volunteer Moderator
    2018-07-10T15:56:10+00:00
    0 comments No comments
  2. Anonymous
    2018-07-10T14:32:27+00:00
    0 comments No comments
  3. Andreas Killer 144.1K Reputation points Volunteer Moderator
    2018-07-10T14:01:59+00:00

    In this case it is easier (for you and for me) if I make the basic changes.

    Please upload your file (maybe with anonymous data) on an online file hoster like www.dropbox.com and post the download link here.

    A macro to anonymize data in selected cells can be downloaded here:

    https://www.dropbox.com/s/rkfxuh85j5wyj9y/modAn...

    Andreas.

    0 comments No comments
  4. Anonymous
    2018-07-10T13:47:22+00:00

    Thank you Andreas - Unfortunately, I don't understand VBA enough to understand your suggestion.

    0 comments No comments