excel-vba

Best short examples of the need for Excel VBA

Here's one for Joel... I am looking for ways to demonstrate to an Excel user (with no programming experience) how learning some Excel VBA can make their life working with Excel a little easier. First thoughts are to use an example that replicates manual tweaking of a spreadsheet, such as one click conditional formatting of all the data...

Source control of Excel VBA code modules

I'd like to be able to source control my Excel spreadsheet's VBA modules (currently using Excel 2003 SP3) so that I can share and manage the code used by a bunch of different spreadsheets - and therefore I'd like to re-load them from files when the spreadsheet is opened. I've got a module called Loader.bas, that I use to do most of the ...

How to shell to an exe and pass cell values from Excel worksheet.

Is this possible in Excel? I have a workbook with multiple worksheets. I wrote some vba code in a code module to shell to an exe and pass it cell values as arguments. What I want to be able to do is select a cell or row in any of my worksheets and then call my Shell Sub while passing the values from a couple cells to the Sub. A hot-key...

Can I use RegFree Com with an application written in Excel VBA?

I have an application that is written in Excel VBA, myApp.xls. Currently we use InstallShield to distribute the application. Since we are moving to Windows Vista, I need to be able to install the application as a standard user. This does not allow for me to update the registry during the install process. In addition to the excel appl...

How do you copy the contents of a Cell into the Clipboard

I'm trying to copy the cell contents into the clipboard. I've read and tried the exact example provided in the Excel 2007 Help file. However for some reason the DataObject object is not valid. So the example: Dim MyData As DataObject Private Sub CommandButton1_Click() Set MyData = New DataObject MyData.SetText TextBox1.Text ...

How to sort multi-row entries in Excel?

So I have a document with many entries that follow this general format. Organization Name Title Address Phone Fax Description line 1 Description line 2 Organization's website. Organization Name Title Address Phone Fax Description line 1 Description line 2 Organization's website. Organization Name Title Address Phone Fax Descrip...

Detecting nulls in Excel VBA

In a program i'm currently working on i've created a user defined type to contain some data that i'll later use to populate my form. i'm using an array of that user defined type and as i pull more data from a offsite server i'm resizing the array. So in order to make my program easier to digest i've starting splitting it into subroutin...

How to capture worksheet being added through Copy/Paste in Excel VBA

I am trying to capture worksheets being copied in to a workbook from another workbook. Workbook_NewSheet event does not trigger when the sheets are copied from another workbook. It is triggered only if the user manually inserts them through (Insert->Worksheet menu option), or when you add a new sheet through VBA as ThisWorkbook.Workshee...

Get the key of an item on a Collection object

The environment is that the members I'm pushing into the Collection are nameless, un-identifiable (to avoid bad abstractions, and please, don't freak out: members are actually other Collection instances). In order to be able to make fast searches, I'm creating a meaningfull hash name for each new member, and provide it as the Key string,...

Excel VBA - Multiple cell update based on a change in ONE cell

I want to fill a range of cell in Excel, when another one changes. I have a macro which can retrieve customer details from another master workbook (WB2), based on the project number. Project numbers are in WB1 as a list. As and when user selects a project number from WB1, I need to fill cells in the range of H9:H15 (in WB1) with custom...

Unlock cell on a condition from adjacent cell

I have two columns but the codition I would like is to be evaluated from one cell to another. The first column has cells which have a drop down validation with names, and the second will activate only if a certain name from the adjacent cell is selected. so far i only found this code but it does not seem to work: Private Sub Worksheet...

VB / VBA StrComp or =

What, if anything, is the benefit of using If StrComp(strVal1, strVal2, vbTextCompare) = 0 Then as opposed to using If strVal1 = strVal2 Then If Option Compare Text is set at the module level, is there any difference? I know StrComp handles null scenarios and <> scenarios, I am only interested in the situation where strVal1 and st...

Converting the Text into Number

Morning All, Today i came up with the new assignment of Converting the Text into number automatically by VBA Codes. For Example '1233 need to converted to 1233 and (1234) need to converted to -1234 without any human interference. Some Advice is very helpful. Regards, A Jabeer Ali ...

how to sort then copy from one tab to another tab and erase what you copied

I have a spreadsheet with 2 tabs. Pension Log and Pension Log closed. On the Pension Log, I can sort by a number of fields. This is the macro I have set up to run for the sort: Sub Sort_Status() ' ' Sort_Name Macro ' ActiveSheet.Unprotect Range("A1:L3654").Select Selection.Sort Key1:=Range("j2"), Order1:=xlAscending, He...

Excel Doesn't Auto-Fit 45º Text

When I orient column headers at 45º I have to manually resize each column since Auto-Fit won't let the oriented text overlap with the neighboring cell. Is there a way to programatically (with VBA) auto-fit the columns where they'll overlap? I'd like a solution which takes font size into account too. ...

Textbox in custom toolbar.

Is it possible to put textbox control in custom toolbar in Excel. I have created an Add-in that shows this toolbar. What I want to do is when user types in textbox Add-in should call a procedure or function depending what user has typed. I would like to do it in VBA in MS Excel. Thanks. ...

Re-assignment of Macro to Command button when copying file.

Hello I have a problem in XL regarding redefining the Macro assignment of radio button when the source worksheet is copied to a Destination worksheet within a new workbook. When i click on the radio button in the Destination worksheet, it attempt to open the Source workbook RATHER to run the macro assigned to the button. I have check...

Speed up pivot table filtering VBA code

I have a pivot table with a pivot field and contain many items. I've VBA code logic to decide if the pivot value should be visible or not. The problem is excel recalculates pivot table for each field shown or hidden which makes it very slow. I would like something where it recalculates only once, after all the values are set. I tried usi...

Add Together - vba

I would like help, if possible, with a code that will do the following… Column B has 10 different variations of contents that are always 10 characters long, starting in cell B2. I would like to make the 10 different variations of contents in Column B into headers for row 1 starting in Column C. Next I would like the macro to look at t...

Divide an Integer by a time using VBA (Excel)

I am trying to divide a sum of integers by a sum of [h]:mm:ss to get [s]. I am doing this by what seems to me to be this wild contortion. temp = Split(Format(Range("D" & rInx).Value, "hh:mm:ss"), ":", -1, vbTextCompare) answerDelay = CInt(temp(0)) * 3600 + CInt(temp(1)) * 60 + CInt(temp(2)) Because this seems rather odd to me I thoug...