Excel 2013 VBA formatting Listbox 2 columns

Have 2 listbox - Listbox 1 has 9 columns and is populated by Excel Worksheet Range. Listbox 1 shows formats correctly.
User selects multiple items from Listbox1 and click a command button to inserts into Listbox2. In Listbox2 the 5th column should show data as h:mm but does not it looks like text. Also, in Listbox2 column 9 should be formatted as date mm/dd/yy and it
is not.
How do I write the code to format these columns?
Code for the Command button is below:
Private Sub CmdInsert_Click()
    Dim IndexRow As Long
    Dim IndexCol As Long
     With ListBox1
         For IndexRow = 0 To .ListCount - 1
             If .Selected(IndexRow) Then
                 ListBox2.AddItem .List(IndexRow, 0)
                 For IndexCol = 1 To .ColumnCount - 1
                     ListBox2.List(ListBox2.ListCount - 1, IndexCol) = .List(IndexRow, IndexCol)
                     Next
              End If
         Next
     End With
Me.ListBox1.MultiSelect = fmMultiSelectSingle
 Me.ListBox1.ListIndex = -1
 Me.ListBox1.MultiSelect = fmMultiSelectMulti

A listbox displays the text of the cells in its rowsource. But rowsource can only be a block of cells, so your code needs to read the text from the source cells of listbox1.
    With ListBox1
        For IndexRow = 0 To .ListCount - 1
            If .Selected(IndexRow) Then
                ListBox2.AddItem .List(IndexRow, 0)
                For IndexCol = 1 To .ColumnCount - 1
                    ListBox2.List(ListBox2.ListCount - 1, IndexCol) = _
                    Range(ListBox1.RowSource).Cells(IndexRow + 1, IndexCol + 1).Text
                Next
            End If
        Next
    End With

Similar Messages

  • Excel 2013 VBA Compatible with Excel 2010

    Hello,
    I am new at working with VBA and have a question regarding an excel sheet with a VBA macro inserted.
    The sheet was created in Excel 2013 by another user, and my laptop runs Excel 2010.  I get script errors when I run it, however on Excel 2013 it works fine.
    My question is: Is there a way to make Excel 2010 work with Excel 2013 VBA scripts? Perhaps importing the library from Excel 2013 VBA to E-2010?  Or perhaps a way to save a VBA script in E-2013 to be backwards compatible with E-2010?
    Thank you all for your support.

    Open the workbook.
    Select Tools > References...
    The references that are in use have their check box ticked. They are all at the top of the list. Do any of those start with MISSING?
    Regards, Hans Vogelaar (http://www.eileenslounge.com)

  • Activate A Second Worksheet In Excel 2013 VBA

    I have an Excel 2013 workbook with 2 worksheets:
    1) Summary   MNA.Sheets("Summary")
    2) Agreement 1  MNA.Sheets("Agreement 1")
    I've tried all sorts of code to get from 1 to 2 in VBA, but keep getting an error.
    What is the proper code?
    Thanks.
    A. Wolf

    Have you tried
    Worksheets("Agreement 1").Select
    Regards, Hans Vogelaar (http://www.eileenslounge.com)

  • Excel 2013 Conditional Formatting problem

    Hello!
    A customer of mine has recently transitioned from Office 2007 to Office 365. This has been a major hurdle for them, and they're still experiencing some issues with things not behaving the way they used to. I'm not an Excel expert, so I have no idea if the
    following issue is some sort of bug or compatibility issue, or if the user is just expecting behavior that isn't going to occur in this version of Excel.
    She has a spreadsheet that she uses to schedule people. She uses conditional formatting to change the color of numbers based on their size. For example, everything less than 2 is red, everything between 2 and 4 is green, etc.
    So, let's say she has two rows that have been formatted already. Then she adds a third row, inputs the data, then highlights the entire row and tries to format it. Once she adds her rules and clicks "Ok", that row is formatted...but rows 1 and
    2 have now been cleared of all formatting. So basically, she can't format things on the go, as she puts them in, she has to format everything at the same time, every time.
    It doesn't happen to every row that has already been formatted. If she has 20 rows that are formatted, sometimes only 2 of them will lose their formatting after she applies her rules to a new row. It's usually the rows that are right next to the new row.
    I have very little experience with Excel conditional formatting, so I don't know what would cause this, or if there's a fix or workaround. Also, I'm not sure if I'm explaining it clearly. Any help or suggestions would be welcome!

    Hi,
    According to your description, this issue seems occur with the special spreadsheet. In my view, it might be more related to the file itself, such as incorrect range with conditional formatting rule, double rule with same cell range or other.
    would you like to send the sample file to me ([email protected])  if possible? I want to test it.
    Regards,
    George Zhao
    Forum Support
    Come back and mark the replies as answers if they help and unmark them if they provide no help.
    If you have any feedback on our support, please click "[email protected]"

  • Excel 2013 - conditional format with dates

    Hi
    I have a workbook that logs courses people have been on and I type in the date the qualification needs to be renewed. I would like that cell to change colour when it is so many days before the renewal date using the =today() function.
    pale yellow - 60 days before renewal date
    orange - 30 days before renewal date
    red - expired, i.e. today's date is after the renewal date
    I have an idea how to do it but I can't seem to get it working exactly the way I want it to.
    Thanks.
    Viv
    Viv Haig

    Select the cell or cells. I will assume in the following that A2 is the active cell within the selection.
    On the Home tab of the ribbon, click Conditional Formatting > New Rule...
    Select 'Use a formula to determine which cells to format'.
    Enter the formula
    =AND(A2<>"",A2<TODAY()+60)
    Click Format...
    Activate the Fill tab.
    Click More Colors...
    Select pale yellow.
    Click OK three times.
    Repeat the above steps, but with the formula
    =AND(A2<>"",A2<TODAY()+30)
    and with orange.
    Finally, repeat them again, but with the formula
    =AND(A2<>"",A2<TODAY())
    and with red.
    Regards, Hans Vogelaar (http://www.eileenslounge.com)

  • Excel 2013 VBA 7.1 Workbook Activate Problems

    I have 2 workbooks open and during the course of a macro am switching between them. The macro has developed a problem where it seems to disregard the workbook.activate command when running. If I set a breakpoint at the line with the activate command
    and step through it, it works fine.
    I have tried activating using ThisWorkbook,Worksheets().activate, Workbook(xx).activate, Windows(xx).activate. I have also tried minimizing the other window which I do not want activated, but this causes the main macro to freeze.
    This is only a problem at one point in my macro and it works properly elsewhere.

    I have 2 workbooks open and during the course of a macro am switching between them. The macro has developed a problem where it seems to disregard the workbook.activate command when running. If I set a breakpoint at the line with the activate command
    and step through it, it works fine.
    I have tried activating using ThisWorkbook,Worksheets().activate, Workbook(xx).activate, Windows(xx).activate. I have also tried minimizing the other window which I do not want activated, but this causes the main macro to freeze.
    This is only a problem at one point in my macro and it works properly elsewhere.
    There is no need to "switch" between the workbooks, just assign a reference to them, and access the methods and properties for each workbook.
    Dim wb1 as Workbook, wb2 as Workbook
    'assuming both workbooks are already open
    Set wb1 = Workbooks("Name of First WB")
    Set wb2 = Workbooks("Name of Second WB")
    Also unless you really need to observe what the macro is doing during execution, there is no reason to have multiple Workbook.Activate statement. Just have one final one at the end of the macro to activate the workbook you really want to see at the end of the
    macro execution.

  • Excel 2003 to 2013 VBA migration bug

    Hello!
    I need to convert mission critical workbooks with much VBA code from Excel 2003 to Excel 2013, of which some were originally created using Excel 97.
    When running any VBA macro I get 0x80028018 errors. A similar problem is described in KB320369 - BUG: "Old format or invalid type library"
    error when automating Excel - however in my case it's
    VBA, not .NET or VSTO and
    I have installed the proper language packs.
    I need to describe more detailed:
    Even when I open the legacy workbook in 2013, create a new blank sheet, delete all old sheets and all VBA code, forms etc., put a new command button in, calling any new VBA sub, I get that error.
    When I create a new workbook from scratch, put a new command button in, calling any new VBA sub, there is no error!
    It also makes no difference, if I save it in compatibility mode xls or as new xlsm. See the screenshots.
    I believe there is some legacy metadata in vbaProject.bin, which makes Excel 2013 choke.
    Thanks!
    L.
    Run-Time Error Message:
    Comparison of the zipped contents of "Book2", the newly created workbook, and "L_VK_1_min", the converted legacy workbook:

    Hi asklucas,
    Are you installing mutiple version of Excel on the same computer? Can you check the wether the reference is correct in tools-reference?
    >>I believe there is some legacy metadata in vbaProject.bin, which makes Excel 2013 choke.<<
    Is it helpful that conver the XLSM to XLSX, then copy the code in to XLSX and save it to XLSM back?
    If not, I suggest that you create a new workbook and copy the orgial code into the new workbook as a workaround.
    Event if there are many workbook, we can write an application to automate this process. Here are some helpful links for your reference:
    Objects (Visual Basic Add-In Model)
    OfficeTalk: Display a List of All VBA Procedures in a Workbook from the Ribbon
    Hope it is helpful.
    Regards & Fei
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • CSV to Excel 2013 - Issue with number format

    Hi,
    I use Excel 2013 to manipulate CSV files. I experienced issue with number format cells. In my CSV file there is one column that presents latitude values in format: 52.05456464. When I open my CSV file in Excel 2013 all values in that column get separator
    ".", in this case my number is present like this: 52.054.454.464. I tried to change my cell format, and when opened the category was Number, I change it to the General but in that case I lost all "." and got 52054454464.
    I also tried to open same file on other machine with Excel 2010 and file is opened correctly without issues and in cell format the category is general by default.
    I hope that there is some kind of resolution for this.

    Hi
    According to your description, we may follow these steps:
    highlight the column B > Home Tab > Number section > Select Number and choose "More Number Format" > Make sure the Negative number is chosen correctly. If you are using Custom format, we will have to change it.
    Hope it helps
    Best regards

  • Excel 2013 Object Model - Conditional Formatting

    1) I'd like to understand the new Excel object model more thoroughly. Can anyone suggest a book?
    2) Are the formulas and/or format settings for conditional formatted cells stored in the object model or in the workbook?  I'm guessing the workbook.
    Thanks.
    Ross

    1) The object model for Excel 2013 is the same as that for earlier versions, with a few additions and omissions.
    See http://spreadsheetpage.com/index.php/books for lots of books about Excel, including programming.
    2) Conditional formatting is stored in the workbook, but you can manipulate it with VBA.
    Regards, Hans Vogelaar (http://www.eileenslounge.com)

  • Excel 2013 connect to a cube, and Power View concatenate the column name by default

    Hi Guys,
    Currently, we met a problem with excel services to connect to a cube, when we develope a Excel 2013 Powerview report, the data model column name is concatenate into terrible name by default. e.g. Dim TimeDate Date, Dim TimeTime HierachyYear -Month.
    But when start up the data model with Powerpivot, everything gone well. We knew that it can be manual update the name as workaround, but we need to do it every time we create a new powerview with the data model.
    Is that any other solution we can do with?
    Please help.
    Johnny

    Hi,
    As this question is more related to PowerView Report, I suggest you can create a new post in the PowerView forum, you will get more helpful information from there.
    PowerView Forum:
    https://social.technet.microsoft.com/Forums/en-US/home?forum=powerview
    Best Regards
    Forum Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact
    [email protected]
    Jerry Guo
    TechNet Community Support

  • Excel 2013 save as JPG/PNG graphic format?

    Dear All,
      For Excel 2013, is it possibe to save the sheet in JPG or PNG graphic file?

    Hi,
    Currently, Excel 2013 doesn't have the ability to save a sheet as an image.
    The simplest way to accomplish this is to select and copy the worksheet cells containing the data, chart, etc. you want to save as an image (turn off grid lines if you don’t want them too), then paste it into your graphics editor, say Microsoft Paint.
    Now you will be able to save it as any graphic formats as you want by using
    Save as feature in Microsoft Paint.
    Regards,
    Ethan Hua
    TechNet Community Support
    It's recommended to download and install
    Configuration Analyzer Tool (OffCAT), which is developed by Microsoft Support teams. Once the tool is installed, you can run it at any time to scan for hundreds of known issues in Office
    programs.

  • Date and Cost formats in export toward Excel (2013)

    Hi,
    I'm trying to export Start date and Cost of my project tasks to Excel:
    File/Save as/ Excel Workbook...
    but all these date and cost data arrive in Excel with Text format. With the 2003 version, date and cost formats were well recognized.
    I'm using Project 2013 English and Excel 2013 English on a French Win 7.
    What are the settings (decimal separator...) which are needed to allow this feature ?
    Thanks

    Hi Julie,
    Thanks for your help.
    The "Convert to Number" feature works fine for the Cost.
    But the dates arrive as text with a long format such as "03 August 2015 08:00" and the  =DateValue(Cell
    reference) function returns an error : #VALUE!
    Any idea to retrieve the dates?
    Thanks again

  • PowerPivot Excel 2013 crashes after column rename in source datatabase

    Hello,
    Using Windows 8.1, Excel 2013 64Bits, PowerPivot Add-In :
    Not using a SQL Server TabularModel just a local Excel Model.
    Having 32MB Ram  memory.
    Readed a table from a SQL Source that contains 13.000.000 records. After loading I discoverd that in the Source one of the columnn names is incorrect. It's name ExecudingProvider and should be ExecutingProvider, so I changed the SQL Server source table and
    added the "t" to ExecutingProvider...
    Back in PowerPivot I do go to the PowerPivot Data model > Design > Table Properties (not sure of translation using dutch edition but you should be able to find it)
    It mentions that it is missing the ExecudingProvider. It;s indeed gone from the Columns that are listed, in place I do see the ExecutingProvider column which is not selected, clicked the checkbox to select the new column name. When clicking Save PowerPivot
    starts loading. On reach of 13.000.000 records PowerPivot crashes saying an error has occurred, no real specification on what error and restarts excel automatically.
    My work arround for know is to remove the table from the model and add it again, causing to recreate all relation ships. This should not be the case I think.
    Do other have this same problem and did you figure out what is going wrong?
    Regards,
    Arjan

    In the event view of the Notebook I can only see the following related errors:
    Faulting application name: EXCEL.EXE, version: 15.0.4603.1000, time stamp: 0x53162a3a
    Faulting module name: EXCEL.EXE, version: 15.0.4603.1000, time stamp: 0x53162a3a
    Exception code: 0xc0000005
    Fault offset: 0x000000000070c3eb
    Faulting process id: 0x1f9c
    Faulting application start time: 0x01cf84820bcf4ee4
    Faulting application path: C:\Program Files\Microsoft Office\Office15\EXCEL.EXE
    Faulting module path: C:\Program Files\Microsoft Office\Office15\EXCEL.EXE
    Report Id: cb310f11-f094-11e3-9cbd-6c626d373f9c
    Faulting package full name:
    Faulting package-relative application ID:
    And
    The program EXCEL.EXE version 15.0.4603.1000 stopped interacting with Windows and was closed. To see if more information about the problem is available, check the problem history in the Action Center control panel.
    Process ID: 1cc0
    Start Time: 01cf84a1a42cd29e
    Termination Time: 0
    Application Path: C:\Program Files\Microsoft Office\Office15\EXCEL.EXE
    Report Id: ffbd693c-f099-11e3-9cbd-6c626d373f9c
    Faulting package full name:
    Faulting package-relative application ID:

  • Excel 2013: Lost VBA Code From Excel 2010

    Just upgraded from Office 2010 to Office 2013.
    Tried to open several of my Excel spreadsheets created in 2010 with Excel 2013. I have spreadsheets that have VBA to perform several functions and routines.
    None of the .xlsm spreadsheets from 2010 work in 2013. I get the following messages:
    "The Visual Basic for Applications (VBA) macros in this workbook are corrupted and have been deleted. The macro corruption most likely exists in the current file. To recover the macros, open a backup copy of this file if you have one."
    OR ...
    "We found a problem with some content in '*******.xlsm'. Do you want us to try to recover as much as we can? If you trust the source of this workbook, click Yes."
    Clicking Yes does not help. It removes or tries to fix the issue. Under the developer tab, the "Visual Basic" and "Macros" button is disabled.
    I tried 3 of my different workbooks. They all get the same error. I went back to an Office 2010 installation and all the workbooks open file - without error, and the code executes.
    Advice?

    I'm getting the same problem, but with Excel 2010.
    I've created a workbook with macros in Excel 2010 and couldn't run it in two computers with office 2010. The same problem as above occurs:
    "The Visual Basic for Applications (VBA) macros in this workbook are corrupted and have been deleted. The macro corruption
    most likely exists in the current file. To recover the macros, open a backup copy of this file if you have one."
    This problem happened with other 2 workbooks with macro. It's curious too that another workbook with macro created by
    me is working on these two computers without errors. And, of course, all of the workbooks mentioned works well in the other computers. This problem started when I downgrade the office os this two computers from 2013 to 2010.
    None of the solutions proposed above has worked.
    Any ideas?
    Thanks in advance!

  • Losing formatting when Share/Un-share Excel 2013

    Hello all
    We're using Excel 2013 on Windows 8 32 bit.
    We are having major concerns with the formatting of these files. It’s sort of hard to explain but we get it all set the way we want it and then if we share or un-share it we lose all our formatting.

    Hi,
    Did this issue occurred with a particular file? Which type of formatting did lost? Generally speaking, If we are saving it in the older Excel 97-2003 format, then it is possible that the losses you are seeing are due to the formatting not being supported
    in the older format. This is particularly true with colors and conditional formatting. Please try to save it as Excel 2013 format.
    If this issue still exists, do you mind sending us a sample file? Email:
    [email protected]? So I can test it from my side. Please use thread link or the subject of this post as mail subject.
    Regards,
    George Zhao
    Forum Support
    Come back and mark the replies as answers if they help and unmark them if they provide no help.
    If you have any feedback on our support, please click "[email protected]"

Maybe you are looking for