Results 1 to 4 of 4

Thread: [RESOLVED] Format Cells

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2008
    Posts
    167

    Resolved [RESOLVED] Format Cells

    I AM Scrapping excel to Attachmate
    in excel each cell has different format
    i need to have format in macro in general
    how do i format the cells in macro

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Format Cells

    cell or range numberformat, is the format of the cell/s
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Mar 2008
    Posts
    167

    Re: Format Cells

    westconn
    i want the format cell genaral
    becasue for example if i have in cell e has 09000
    only if the format is in generl we can enter 000
    if it is number it shows only 9000
    if it is text it shows only 9000
    if it is general we cna enter 09000
    how do i write in vba code
    and my code fully cell(1, "e") it works find
    but i saw here range("e1") and cells(1, 5)
    if iput cells(1. "e") it works i dont find any problem but does it affect anything
    i learned lot from you Westconn. you explalin this also.

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Format Cells

    i think you have it round the wrong way, in general it will only allow numbers to be numbers (leading zeroes will be removed), numbers prefixed with zero are strings and can only work if the cell is formatted as text
    to format range /cell as text
    range("a1").numberformat = "@"
    to format as general
    range("a1).numberformat = "general"

    and my code fully cell(1, "e") it works find
    but i saw here range("e1") and cells(1, 5)
    if iput cells(1. "e") it works i dont find any problem but does it affect anything
    it makes no difference as far as i am aware, which of those you use and there are some other methods too, like r1c1
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width