excel-vba

Return values only if they are not present in current column

I have a column to which I am adding data from another column I would like to check whether that column has the data that I wish to add. Can you help me with a formula that will tell me whether a certain value exists in the current column? Please keep in mind it is a bit more complex than it sounds. Currently I have this in the cell: ...

What is the C# equivalent of this Excel VBA code for Shapes?

This is the VBA code for an Excel template, which I'm trying to convert to C# in a VSTO project I'm working on. By the way, it's a VSTO add-in: Dim addedShapes() As Variant ReDim addedShapes(1) addedShapes(1) = aBracket.Name ReDim Preserve addedShapes(UBound(addedShapes) + 1) addedShapes(UBound(addedShapes)) = "unique2" Set tmpShape ...

Excel VBA: NetworkDays Error 2015

Hi All, I have the this bit of code in a VBA class which is to workout the number of days between a property of the class (a date) and today’s date. Dim EmailDate As Date EmailDate = Me.Email.DateReceived Debug.Print EmailDate, Date Debug.Print NetworkDays(EmailDate), Date, Range("BankHolidays")) When I run it I get the following ou...

How do I run some VBA code when a cell is changed?

I want to add some VBA code when the value in a cell changes. I've already tried Worksheet_Change(), as described at http://www.contextures.com/xlfaqmac.html#WSChange However, this won't work: it only fires when the user changes the value. I want to fire it whenever the value changes, i.e. whenever the spreadsheet recalculates. Any id...

Automatic Data sorting/ analysis in Excel

I have data in the form of four columns. The first three columns represent time, value1, value 2. The fourth column is binary, all 0's or 1's. Is there a way to tell excel to delete time, value1 and value 2, when the corresponding binary value in column four is 0? I know this is a lot easier in C++ or matlab, but for reasons beyond my c...

Creating an Excel Template for different data size

I created an excel template for a file i've done for a routine work calculation. The file takes data from the data logger and does some analysis on it and outputs one number regardless of the input size. The problem I'm having is i have to modify the sheet to suit the number of rows, as everyday the data logger outputs a different num...

Excel + Web Data

I've spent hours scouring the net for anything to do with VBA calling data from the web in excel and nothing provides a tutorial on how to do so, only complicated examples un-related to what I want to do. I want to pull data from either a .html or .xml site, doesn't matter, via Excel and find specific points in that data. I can find spe...

Dynamic Chart Series Labels

I have some Visual Basic Code that creates a chart for each row. It sets the series values using this code: .SeriesCollection(1).Values = "=" & Ws.Name & "!R" & CurrRow & "C3:R" & CurrRow & "C8" What I am struggling with is how do I set the series labels? The series labels will always be the 1st row and be in the corresponding column...

Changing Positions of the Chart When Creating Multiple Charts Automatically via Vbasic in Excel 2007

I am creating a new chart for each row of data in an Excel spreadsheet. I have the Vbasic working properly, but I want to change the position of the chart on the sheet that is added for each row. Below is my code, what do I need to do to change the position of the chart on the page automatically? Ideally, I would like it to be in th...

Open an Access database and run one of its Macros from Excel

From Excel, I need to open an Access database and run one of the database's macros. I'm using Excel and Access 2007. Here is my code in Excel: Sub accessMacro() Dim appAccess As New Access.Application Set appAccess = Access.Application appAccess.OpenCurrentDatabase "C:\blah.mdb" appAccess.Visible = True appAccess.D...

Allow paste in worksheet without overwriting locked cells

I have a protected worksheet that users would like to copy and paste into. I have no control over the workbook they are copying from. The protected worksheet has some rows that are available for data entry, and other rows that are locked and greyed out to the user. The users would like to be able to paste over the top of the entire work...

Duplicate what is in the Textbox in other Textboxes on other sheets

I have four sheets in a spreadsheet. On each sheet there is a textbox. When I type in the textbox on sheet1, I want the textboxes on sheet2, sheet3, and sheet4 to populate with the same value. ...

Microsoft.ACE.OLEDB.12.0 has not been Registered" Error

I'm getting a "The OLE DB provider "Microsoft.ACE.OLEDB.12.0 has not been registered" error. I have the data objects library downloaded and I have "Microsoft Office 12.0 Access database engine Object Library" selected. I'm running the Windows Vista 32-bit operating system. Any ideas would be greatly appreciated. ...

IF Statement in VBA

How would I code a IF statement if I was trying to say IF the date today is equal to Monday THEN Have Outlook prepare 3 emails ELSE Have Outlook prepare 2 emails END IF I just need help setting up the "IF the date today is equal to Monday." How would that code look. Set omail = CreateItem(olMailItem) With omail .Subje...

FTP a text file to a server using VBA in Excel

I have an Excel worksheet where the user enters certain data, which I want to store in a text file and upload to a server using FTP. One site suggested adding a reference to "Microsoft Internet Transfer Control" and then define an "Inet" object to do the FTP. However, I am unable to find a reference with this name in "Tools -> References...

vba: what does ReDim Preserve do and simple array question

i am looking at someone else's vba excel code. they are doing ReDim Preserve dataMatrix(7, i) in both loops. what does this do? also, it seems like the second loop just overwrites the data in the first, loop, is that correct? Dim dataMatrix() As String Worksheets.Item("ETS").Select Do While Trim(Cells(r, 1)) <> "" Debug...

Concatenation yields error with underscore

I am trying to create a macro that brings in the name of the sheet and combine it with text. For example, for sheet one, I want it to say "ThisIs_Sheet1_Test" in I5 of Sheet1. There are several sheets but it should work for all of them. What is wrong with my code? I think the underscore might be ruining it all. Here's what I have: Dim ...

C++ Excel AddIn DLL that returns strings to C# and VBA

I'm in the process of creating an Excel addIn package to work with a web service. I have a C++ .xll addIn that uses MSXML to communicate with the web service, and registers worksheet functions, but otherwise provides no UI. I am developing a c# .net addIn to provide the GUI using the Office 2007 ribbon, and a VBA addIn for earlier versi...

Pull in Earlier Value Using Concatenation

I have code that works in some situations but not in others. I have this code: Public Sub ListBox2_LostFocus() ListBox2.Height = 15 With ListBox2 ThisIs_Sheet1_Test = "'" For i = 0 To .ListCount - 1 If .Selected(i) Then ThisIS_Sheet1_Test = ThisIs_Sheet1_Test & .List(i) & "','" End If Next i End W...

Insert the Formula in Excel Cell Using Vba

hi I am populating the data from MS Access to Excel through VBA. The data are populated in the Range (A to I ).I wants to insert the Formula in each excel cell during the population time. i trying this code varConnection = "ODBC; DSN=MS Access Database;DBQ=D:\sample\table.accdb; Driver={Driver do Microsoft Access (*.accdb)}" varSQ...