How to automatically apply the file path from a cell in VBA?

Now I am using this code for running a Excel Chart Template on bar charts: Apply Saved Chart Template ActiveChart.ApplyChartTemplate ( _ "C:\Users\Bosco\AppData\Roaming\Microsoft\Templates\Charts\Bar Chart.crtx" _ ) Since this link will be decid

How to save all hard-coded values ​​in a class

I have created a class in VBA which I would like to have some pre-set values associated with it. I am new to classes, and am wondering what is the best (/a good) way of structuring my VBA code within the class object, so that I can access these defau

Excel VBA - Execute an SQL stored procedure error

I have the following code in my Excel workbook that I copied from this page. Code: Sub Button1_Click() Dim con As ADODB.Connection Dim cmd As ADODB.Command Dim rs As ADODB.Recordset Dim WSP1 As Worksheet Set con = New ADODB.Connection Set cmd = New A

Excel VBA retaining the first 3 digits in commas

I have thousands of lines of raw data I need to manipulate. It looks something like:,,, and so on.. I just need the first 3 numbers so I want to be le

VBA code does not always save in the office

I have a piece of code in most cases will save to the desktop, but sometimes when I am connected to the network, it will save into a network folder. I am keen for this to always save it in my desktop in all cases. Sub Svas() Dim Name As String FilePa

unable to reset the used range

I was trying to add an automatic macro to my very large workbook to at least trim some fat off by resetting the used range. I've tried numerous codes and cannot get it to work and can't figure out why. (It seemed to work a few time when I would manua

Excel- How to lock a formula used as a defined name?

So I created a "name" in my workbook to help me use a macro to run an advanced filter. Here is the formula: =OFFSET('Property Data'!$A$6,,,COUNTA('Property Data'!$A$5:$N$69),14) This works fine except that I have a "delete" function wr

How to call a subset of subroutines with a loop in VBA?

I have a series of subroutines (Sub1, Sub2, Sub3, etc). I want to call a subset of these subroutines based on user defined values. For example, subs 7 through 13. I thought of using a loop based on the number in the name of subroutine, but it does no

Conditional deletion in VBA

I am trying to piece together code to make my macro work correctly. This approach has served me well in the past but I cannot seem to adapt any code correctly. I found the following Sub way() Dim Cell As Range For Each Cell In Range("A1").Curren

VBA INDEX-MATCH loop with Sub or Function error not defined

I have a looping INDEX-MATCH VBA that I am trying to debug, as it is constantly throwing a Sub or Function not defined error. With what I have already found on this site, I was able to check my references, but I still seem to be missing something ("S

the day and the month are reversed

I have a cell with the following content : 01/02/2015 The cell is date formated Then I copy the value and put it in my module class : Set Line = New CTravelLine Line.Date= Cells(1, 8).value Everything works fine until the moment I put this value in a

Importing files into Excel - Ignore if not found

This is my first question here, I have a macro to import .txt files "Semicolon" delimited into Excel. Each file is name specific, and each file is imported in a new sheet. But if one of theses files doesn't exists, the macro Fails. I want to add

Value of a user-defined function

I have an User Defined Function in Excel 2010 VBA. In a cell A1, I call that function: =myfunction() and the returned value (as Integer) is showed correctly in the A1 cell. My concern is how can I obtain the value of A1 cell from other function in VB

VBA - Get the OLD value of Combobox

I would like to get the old value of a ComboBox when the combobox value will change. I have tried something like: Private Sub ComboBox1_Change() Application.EnableEvents = False newVal = ComboBox1.Value Application.Undo oldVal = ComboBox1.Valu End Su

VBA: Obtaining Line Data When a Cell Is a Specific Value

I'm fairly new to VBA - most of my programming is done in PHP - and I haven't touched anything VB-like since VB5. I've been asked to learn VBA for work and am doing fairly well - but have gotten stuck. Our spreadsheet has 3 sheets (4, including the o

Show milliseconds in Excel

I am trying to display milliseconds in an Excel macro. I have a column of integers which are simply timestamps in milliseconds (e.g. 28095200 is 7:48:15.200 am), and I want to make a new column next to it which keeps a running average and displays th