+ Reply to Thread
Results 1 to 9 of 9

Changing cell and data format using vb

  1. #1
    Forum Contributor
    Join Date
    01-29-2008
    Location
    Scotland
    MS-Off Ver
    2003
    Posts
    237

    Changing cell and data format using vb

    Heres a puzzle

    Im using the code shown below to convert a text number into a true excel time, i.e. 1345 into 13:45, well the code changes it to 1:45 pm and then i have to change to display format to show 13:45

    Please Login or Register  to view this content.
    Instead of doing this conversion in another column, is there a way via vb or a macro to perform this task on two columns of data with a custom menu button etc.

    I want to be able to import my data from a csv file and then click a menu option and have two columns convert to proper time i.e from 1335 to 13:35

    Hope that makes sense

    G

  2. #2
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Changing cell and data format using vb

    This will convert 4 digit text strings to their serial time value:

    Please Login or Register  to view this content.

    Dom
    Last edited by Domski; 07-19-2011 at 10:18 AM.
    "May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."

    Use code tags when posting your VBA code: [code] Your code here [/code]

    Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.

  3. #3
    Forum Contributor
    Join Date
    01-29-2008
    Location
    Scotland
    MS-Off Ver
    2003
    Posts
    237

    Re: Changing cell and data format using vb

    Thanks for that DOM

    But looking at it it looks like the user would have to select the column and then convert the data, is there a way of doing it with out selecting the data, as the columns are the same on the csv sheets as i import them..

    G

  4. #4
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Changing cell and data format using vb

    Like this:

    Please Login or Register  to view this content.

    Change A to the column you want it to work on.

    Dom

  5. #5
    Forum Contributor
    Join Date
    01-29-2008
    Location
    Scotland
    MS-Off Ver
    2003
    Posts
    237

    Re: Changing cell and data format using vb

    Sorry fro also sounding a bit stupid, but not that great with VBA in excel, where would i put that code..??

    Just read your last post, would i need seprate code for each column or could this one bit of code cover a range, as the two columns that need converting are next to each other


    G
    Last edited by drgogo; 07-19-2011 at 10:37 AM. Reason: Read new post

  6. #6
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Changing cell and data format using vb

    Which columns would you like it to work on?

    Easiest place to keep it would be in your personal macro workbook and then it's always available to you. Have a look here how to create one.

    Dom

  7. #7
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Changing cell and data format using vb

    I'm off home now.

    For column A:B the code would be:

    Please Login or Register  to view this content.

    To amend for D:E change this:

    Please Login or Register  to view this content.

    Hopefully you can amend to suit your needs.

    Dom

  8. #8
    Forum Contributor
    Join Date
    01-29-2008
    Location
    Scotland
    MS-Off Ver
    2003
    Posts
    237

    Re: Changing cell and data format using vb

    HIya DOM, just ran your code, kinder worked ok, except it did understand .numberformat

    Also it has affected other cells on my spreadsheet and formatted other things
    Last edited by drgogo; 07-19-2011 at 11:04 AM.

  9. #9
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Changing cell and data format using vb

    I'd probably need to see a sample of your workbook to see what's going on.

    Dom

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1