FAQ Database Discussion Community


VBA - Trapping events on dynamically created Textbox

excel,vba,excel-vba,events,userform
I am writing a VBA application in Excel. I have a Userform that dynamically builds itself based upon the data contained in one of the worksheets. All of the code that creates the various comboboxes, textboxes and labels is working. I created a class module to trap OnChange events for...

VBA Excel SendKeys Macro

excel,vba,excel-vba
I have some result data in sheet Extract that I need to activate cell by cell and press enter. It's alright for 10 cells but I have over 40 000. So i wrote some macro Sub Refresh() Dim lastrow As Long lastrow = ActiveWorkbook.Worksheets("Extract").Range("Q" & rows.Count).End(xlUp).Row For j = 2...

VBA data type to store Range().Characters()

vba
I can't find a data type to store Characters from a Range. I already tried the following code, but nothing happened. I think the problem is because of wrong data type. Dim chars As Characters chars = Range("A2").Characters(0, 4) MsgBox chars.Text ...

Using VLOOKUP formula or other function to compare two columns

mysql,excel,vba,date
I have one table like this: SHORT TERM BORROWING 1/6/2009 94304 12/31/2010 177823 6/30/2011 84188 12/31/2011 232144 6/30/2012 94467 9/30/2012 91445 12/31/2012 128523 3/31/2013 83731 6/30/2013 78330 9/30/2013 70936 12/31/2013 104020 3/31/2014 62345 6/30/2014 62167 9/30/2014 63494 12/31/2014 104239 3/31/2015 69056 I have another column which lists each date from...

VBA - .find printing wrong value

excel,vba,excel-vba
I have two sections of code that basically do the same thing but with two different columns. The code finds the header "CUTTING TOOL" and "HOLDER" (looping through multiple files) and prints the information from those columns into one worksheet, masterfile. I was using a less efficient method of setting...

Msgbox With If statement

vba,excel-vba,excel-2003
I'm trying to get a box to pop up listing a number of values that could be blank. MsgBox (res1 & vbNewLine & _ res2 & vbNewLine & _ res3 & vbNewLine & _ res4 & vbNewLine & _ res5 & vbNewLine & _ res6 & vbNewLine & _ res7...

Copying certain columns VBA

excel,vba,excel-vba
I have a working VBA macro which copies from one spreadsheet 'AverageEarnings' to another 'Sheet1', under the condition that Column AO has the word 'UNGRADED' in it. The macro copies the entirety of these conditional rows to Sheet1. I am looking to copy columns B and C ('AverageEarnings') to columns...

Get access to MS Word macros from PHP

php,vba,ms-word,word-vba
The problem is following. I have a tool that generates .docm files. These files contain some macros. The code of macros has settings information, like URLs, etc. I want to somehow access from PHP this macros in order to make changes programmatically. This is especially necessary when the whole application...

embed object and display as icon in word document?

vba,ms-word,word-vba
I have a word document. In the word document I have command button. What I am after is when the user presses the command button it would open a dialog box so that the user can embed a file and display as an icon within the word document. How WOULD...

Creating a Range in VBA

vba,range
I'm working on my first VBA function. The goal is to have a function that accepts two integers as inputs, and outputs an array containing all the integers in between the two inputs (end-points included). Example: If I input 5 and 9, the output should be an array of 5,...

Delete the Range of Columns in Excel VBA

excel,vba,excel-vba
I am trying to delete the range of columns but getting error "Application Defined or object defined error". In the below code wks is the worksheet and colStart and colEnd are variables with values. Dim colDelete As String colDelete = wks.Range(wks.Cells(1, colStart), wks.Cells(1, colEnd)).EntireColumn.Delete ...

VBA “Compile Error: Statement invalid outside Type Block”

excel,vba,excel-vba,excel-2010
I am running a VBA Macro in Excel 2010 with tons of calculations, so data types are very important, to keep macro execution time as low as possible. My optimization idea is to let the user pick what data type all numbers will be declared as (while pointing out the...

Compare 2 sheets with different headers

excel,vba,excel-vba,compare
I have 2 different files which have different headers, for example: OldfileHeaders | NewFileheaders ID | Test ID Date | New date and so on. I am trying to compare the data in both sheets and see if they match. The rows of data may be in different order and...

Way to capture double click to open file?

excel,vba,excel-vba,add-in
Is there a way to have an Excel macro to check what file I double clicked on to open. When I open that file, the Add-Ins installed load first, then the file I clicked on loads. How can I write code inside one of my Add-Ins to check what the...

Excel VBA range after filtering xlCellTypeVisible

excel,vba,excel-vba,filter,range
What I want to accomplish: Open a workbook from a specific address, Filter the first column for value equal to 36 or 541 (I got this first part working), then check column 3 to see if a value of 2 exists and if it exists then filter out everything except...

Loop Up rows until Value DOES NOT equal Continued

excel,vba
This is a small section of a larger code. basically if the cell contains the word continued I need to look in the cell above, if this cell contains the word continued then I need to continue to loop up the rows until a value which is not continued is...

Run various queries based on a combo box selection

vba,ms-access,drop-down-menu,access-vba
I have a form where a user will select a value from a dropdown. Based on this selection, I would like a series of queries to execute. For example, if a user selects 'A', then queries 1, 2 and 4 would execute. If user selects 'B', then queries 4, 2,...

How do I use the Find function with a variable term, for example Run1, Run2, RunX

vba,excel-vba,loops,variables
Cells.Find(What:="Run:1", After:=Cells(1, 1), _ LookIn:=xlValues, LookAt:=xlPart, _ SearchOrder:=xlByColumns, SearchDirection:=xlNext, _ MatchCase:=False, SearchFormat:=False) This is the code that I want to use, but I would like to loop it to find Run:1, Run:2, Run:3... Etc..., Is there a way to add a variable in a reference to find "Run:X"?...

How to fill the rest of line with space() / string()?

excel,vba,ms-word,word-vba
I am generating a word document filled with user inputed values (userform input). Is there any way to fill the space after typed value with amount of whitespace required to fill the rest of the line? Or how to get the amount of characters left to the end of line?...

I need help setting the RecordSource of a Report within a VBA Function

vba,ms-access,access-vba
Ok, so I've been looking around here for a few days (and a few other sites) and while I have modified my code a good bit to find a solution, it still doesn't work. I have four source queries, and I'd like to set the record source of my report...

Right function vba

vba,excel-vba
I want to take everything to the right of the symbol in the string I used Right(enclosedValue, InStr(enclosedValue, "*") - 0) where enclosed value is 29,6 *60, so I need it to return *60, but now it returns ,6 *60 Sorry if this question has been asked already, I have...

Interface Controls for DoEvent in Excel

excel,vba,excel-vba,loops,doevents
I have a macro to loop through a range and return emails to .Display based on the DoEvents element within my module. I iterate that: row_number = 1 'And Do DoEvents row_number = row_number +1 'Then a bunch of formatting requirements Loop Until row_number = 'some value I am wondering...

Extract All Named Ranges Into A Class

vba,excel-vba
I have a workbook with a very large amount of named ranges (well over 200). I really need a way to work quickly and easily with all of the named ranges so I can then work with / populate them using VBA. My solution up until now has been to...

Excel 2013 Add a Connector Between Arbitrary Points on Two Different Groups

excel,vba,excel-vba
I'm working in Excel 2013 to (programmatically) add a straight line connector between the lower right hand corner of a rectangle that is part of a grouped shape with the endpoint of a grouped series of line segments. As it stands, I can't even seem to do this manually on...

Changing the active cell

excel,vba,excel-vba,excel-2007
I was looking to create a program that examined a column of text in excel and extracted the first line that contained currency. The currency was in Canadian dollars and is formatted in "C $##.##" with no known upper bound but unlikely to reach 10,000 dollars. I was hoping to...

Excel VBA code for multiple vlookup

excel,vba,excel-vba,match,vlookup
For a conduit network, I am trying to find the pipes that drain to a manhole. There can be multiple pipes that can drain to a single manhole. My data-structure are organized in the following way: - Stop Node Label ........ ................ - MH-37 CO-40 - MH-37 CO-40 - MH-39...

VBA crashes when instatiating 'Match' object

vba
I am puzzled why does following code crashes on line with "'<-----". That being said I get no error message and VBE is set to break on all errors, not just unhandled, nor did I have then time to write the error handing procedures yet. There is also the fact...

VBA - Unable to pass value from Private to Public Sub

excel,vba,excel-vba
I have a tool which I am designing to present a number of questions to a user in a set of userforms. The form will generate a score via passing an integer result from the userform to a main sub, which passes the code to a worksheet. My problem is...

Using date in CreateQueryDef

vba,date,ms-access
I have a table on which I run a query that I export to Excel. Here is an example: Table: Food Item | Price | Limit_Date | ------------------------------- Carrot | 0.80 | 08/07/2015 | Salmon | 4.30 | 01/07/2015 | Biscuits | 2.40 | 15/12/2015 | Milk | 1.00 |...

How do you delete favorite folders in outlook using VBA

vba,outlook-2007
I wish to delete all the folders from the outlook favorites then subsequently replace them, but the delete doesn't seem to work. What's wrong with my code. Setup Objects works fine ' Get the "Favorite Folders" navigation group Set favGroup = Application.ActiveExplorer.NavigationPane.Modules.GetNavigationModule(olModuleMail).NavigationGroups.GetDefaultNavigationGroup(olFavoriteFoldersGroup) This works Set inboxFldr = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox) favGroup.NavigationFolders.Add (inboxFldr)...

How do I do to count rows in a sheets with filters? With a suppress lines

excel,vba,filter
I have a sheet with lots of columns, but when I filter and use count = Application.WorksheetFunction.CountA(Range("A:A")) It returns all the rows non Empty. Not only the rows I filtered....

How to use each value in a range to autofilter data in another sheet?

excel,vba,excel-vba
I'm a bit new to VBA, so was hoping to get some help on this page from you experts! I have the following requirement: I have a table with unique values of Column2 in Sheet2(range) I need to filter out data in Sheet1 using each value in the above range...

ByRef Argument type mismatch on just changing the variable position in declaration

vba,byref
I have defined a function in VBA as follows: Sub TestFunction() Dim ArrayLength, IDvariable, IDComparisonResult, PreArrayLength As Integer ReDim NodesArray(0) PreArrayLength = 0 IDvariable = 0 . . Sort PreArrayLength End Sub whereas the function called is as follows: Sub Sort (PreArrayLength As Integer) . . . end sub Above...

Activecell not in Array

vba
Having difficulty comparing my activecell against a predefined array. After importing data from another source I want to trim out the columns I don't need I've trued the array as both undefined, string and variant And tried activecell / activecell.value <> NeededColumns No joy :( Sub Trim() Dim NeededColumns As...

iteration (for-loop) ms Access with past value

vba,for-loop,access-vba,iteration,recordset
I tried to translate a code from VBA excel to access. My data is a column of prices and I want to compute the returns. This is the original VBA code in excel: DerCol = Cells(T.Row, Columns.Count).End(xlToLeft).Column Cells(T.Row, DerCol + 1) = "Returns" For i = T.Row + 2 To...

VBA to remove special characters before saving workbook

vba,excel-vba,special-characters
I found this function to remove special characters. Function Remove_Characters(s As String) As String Static RegEx As Object If RegEx Is Nothing Then Set RegEx = CreateObject("VBScript.RegExp") With RegEx .Global = True .Pattern = "\\|/|:|\*|""|\?|<|>\|| " End With End If Remove_Characters = RegEx.Replace(s, "") End Function What I want to...

adding variables into another variable vba

excel,vba,excel-vba
Dim x As Long Dim y As Long Dim CDTotal As Double Dim CSTotal As Double Dim ETotal As Double Dim FTotal As Double Dim HTotal As Double Dim ITotal As Double Dim ITTotal As Double Dim MTotal As Double Dim TTotal As Double Dim UTotal As Double Dim TotalValue...

VBA Return Carriage and Fill Code

excel,vba,excel-vba,return,carriage-return
I'm really new to vba and would appreciate any assistance in the following problem I'm having. Problem description (in relation to diagram below): 1*) In c, I have managed to separate the return carriages, which leads to 2*) now that each return carriage has it's own row, I need column...

Count amount of differences and return column name with count

excel,vba,excel-vba
i am finding the differences between 2 worksheets, the code is as follows: For Each mycell In ActiveWorkbook.Worksheets(shtSheet2).UsedRange If Not mycell.Value = ActiveWorkbook.Worksheets(shtSheet1).Cells(mycell.Row, mycell.Column).Value Then mycell.Interior.Color = vbYellow difference = difference + 1 End If If mycell.Value = ActiveWorkbook.Worksheets(shtSheet1).Cells(mycell.Row, mycell.Column).Value Then matches = matches + 1 End If When the...

Errors 91 and 424 when iterating over ranges in Excel VBA

excel,vba,excel-vba,range
I am an absolute VBA beginner. I have been trying to create a function that separates a large range into smaller ranges. However, when I try and iterate over the large range, I get errors 91 and 424 interchangeably. Here is the relevant bit of code: Dim cell As Range...

Compare two data sets in different sheet and print difference in other sheet using excel VBA?

excel,vba
I have two data sets in two different sheet Sheet1 is my Orginal ref and sheet2 is for comparison. sheet2 data should get compared by Sheet1 and print entire mismatched row of sheet2 and highlight the cells which has mismatch data and this difference should be printed with column header...

MACRO that organises, groups, outlines (Need to adjust the area that the macro applies to)

excel,vba,excel-vba
How to apply this from A4 instead of A2. Everything else I am happy with. I just want to understand any changes that I need to make to this. Is it needing changes at "set population"? The 2? Sub formatresults() Dim lastRow As Long Dim pop As Range Dim rpSet...

Using excel as inputfile in vba (scripting - non MS OFFICE)

vba,scripting
I'm developing a script in VBA (inside a workspace, not MS office program) that needs to use a small excel file as input. I want to use the data in the excel file and load it into a 2D array so that I can make decisions within my script based...

Converting ADODB Loop into DAO

excel,vba,ms-access,ado,dao
Hi I've been developing a vba project with a lot of help from examples here. I'm trying to access a MS Access database from Excel VBA and import large data sets (500-100+ rows) per request. Currently, the following loop works using ADODB however, the Range("").Copyfromrecordset line is taking very long...

Formatting specific part of text string in VBA

excel,vba,excel-vba,outlook,format
I am in process of creating a macro that will save the current workbook, create a new outlook message and attach the file to the message. My macro does that but I can not format the text in the body of the email to my liking. Dim OutApp As Object...

Check if excel file is open, if yes close file,if no convert csv file to excel Visual Basic [duplicate]

excel,vba,excel-vba
This question already has an answer here: Detect whether Excel workbook is already open (using VBA) [closed] 7 answers I'm having a problem creating a condition. Please see pseudo code below. thanks in advance Check if File A.xls is open If File A.xls is Open Close File A.xls Else...

using activecell and offset in VBA

excel,vba,excel-vba
I am trying to test offset property in excel vba . I am using a simple code which selects the cell which is daigonal , i.e 1 row and 1 column away from the active cell. This is what I am doing Sub Range_Offset() Range(ActiveCell).Offset(1, 1).Select End Sub I have...

Editing a query in another DB

vba,ms-access,access-vba,ms-access-2010
Is it possible to open a second Access database from within an Access database, and edit a query in that second DB? I know you can open one Access DB from another, but I'm just not sure whether or not you can edit a query that way. If it's possible,...

Finding position of a particular string containing cell in Excel

excel,vba
I am searching for a string using below code For x = 2 To lastrow If Sheets("sheet1").Cells(x, 3) = TFMODE Then ....... 'TFMODE is the string discussed 'This particular string "TFMODE" is randomly recurring throughout 'sheet in column 3. I need to know position for a particular string in sheet1...

Referencing a new inserted column Excel VBA

excel,vba,excel-vba
I am trying to reference a cell in the below formulaes. 'AUA Summary'!$D$9 . Each time the macro runs a new column D is inserted. The Problem: When the column is inserted my reference moves to ** 'AUA Summary'!$E$9. How do I get to reference 'AUA Summary'!$D$9 even if a...

Range, Select, Change contents, Allignment or Offset?

excel,vba,excel-vba
I have a case at the moment where I am moving down the column with the names below and clicking on a macro, that then marks the indicator with a 35, a few columns down to the right. Due to the nature of the page, I am wanting to count...

Hiding #DIV/0! Errors Using IF and COUNTIF in Excel 2010

excel,vba,if-statement
I'm working on a tracking sheet for quality reviews of work completed. I have a list of criteria to be met for which the entry can be either Y or N, or X for not applicable. Each month a number of these reviews will be done on each person. In...

Excel-VBA: create named Range in row until end of cell content

vba,excel-vba,range
Imagine an Excel sheet with some rows and some content in each row (i.e. different column-length for each row). In Excel-VBA: How can I create a range-X within column-X that goes from row-cell-2 to the end of the content of this X-column ?? i.e. I would like to create a...

Replace reference with its value in Excel VBA workbook

vba,excel-vba
I have an Excel workbook to manage my Delivery Notes, which creates another workbook with actual delivery note and stores it in the folder for me, then places new record in my main workbook so that the Delivery Number for the next delivery note can be increased by 1. My...

How do I resolve the “Enter Parameter value” error in MS-Access

sql,excel,vba,tsql,ms-access
This code and another is producing the logical error in Ms-Access where it asks for a parameter equal to an objects name. In this case it wants [DSRT_ERS].[ID]. INSERT INTO DSRT_ERS SELECT * FROM DSRT_TEMP WHERE [DSRT_ERS].[ID] <>[DSRT_TEMP].[ID]; If you look at the DB's documentation you notice it is spelled...

Outlook VBA - set sentonbehalf and Refresh ActiveInspector

vba,email,outlook,outlook-vba
I frequently want to change the sender data in the currently open Mail This is well done by following code: Sub AktiveMailSetVonHotline() Dim oMail As Outlook.MailItem Set oMail = ActiveInspector.CurrentItem oMail.SentOnBehalfOfName = "Hotline@mycompany.de" End Sub` Only question / disadvantage is: After running that macro I can not see that the...

How to manipulate a Word 2013 document opened in read only mode

c#,vba,ms-word,word-vba,readonly
I have to open Word documents for automation in read only mode. Then I have to remove some certain pages from that document, regarding some configuration the user did in the user interface of the program. Manipulation does work for footers and headers, but this particular code doesn't work. It...

Copying sheet to last row of a sheet from another workbook

excel,vba,excel-vba
I'm stuck in this block of code that copies sheet("Newly Distributed") to the last row of sheet("Source") from another workbook. The error is runtime error 9. What's wrong with my code? Any response would be appreciated. Private Sub copylog3() Dim lRow As Long Dim NextRow As Long, a As Long...

Match Function in Specific Column Excel VBA

excel,vba,excel-vba,match,worksheet-function
I'm trying to write a program in VBA for Excel 2011 that can search a column (which column that is is determined by another variable) for the number 1 so that it knows where to start an iteration. Say that the number of the column is given by colnumvar. The...

Excel VBA (via JavaScript) - Moving a Sheet to a new location

javascript,excel,vba,excel-vba
With the following code, I am attempting to move a Sheet in my Excel workbook from one location to another. However, instead of making the move - Excel creates a new Workbook. How do I move a Sheet from one location to another within the same Workbook? /////////////////////////////////////////////////////////////////////////// // //...

Taking value of a range of merged cells

excel,vba,excel-vba
I have a range of merged cells with values in them. I would simply like to read the value contained in each merged cell. The amount of cells in the merge area varies. Right now I have this: Sub testnoms() Dim cell As Range For Each cell In ActiveSheet.Range("B20:K23") 'this...

Recordset.Edit or Update sql vba statement fastest way to update?

sql,vba,ms-access,access-vba,ms-access-2003
I recently came across vba update statements and I have been using Recordset.Edit and Recordset.Update to not only edit my existing data but to update it. I want to know the difference between the two: recordset.update and Update sql Vba statement. I think they all do the same but I...

Best way to return data from multiple columns into one row?

excel,vba,excel-vba
I have a sheet with just order numbers and another with order numbers and all of the data associated with those order numbers. I want to match the order numbers and transfer all of the available data into the other sheet. I've been trying to use loops and VLOOKUP but...

Syntax for DAO 'Like' Select Query

sql,vba,like,dao
I'm sorry for bothering you all for what is probably a really simple problem. I use DAO Select queries fairly frequently but have never needed to filter using 'Like' based on a form field. The attached code, which should filter based on a combobox (comboRes), throws up a Syntax error...

Specifying a range to be applied to all subs in a module?

excel,vba
I have been working on creating a module that has multiple subs and functions that all are applied to the same sheet. In my efforts and research to clean up my code I found that instead of declaring the "Dim" for each sub, I can declare it at the very...

Slow VBA macro writing in cells

excel,vba,excel-vba,ms-project
I have a VBA macro, that writes in data into a cleared out worksheet, but it's really slow! I'm instantiating Excel from a Project Professional. Set xlApp = New Excel.Application xlApp.ScreenUpdating = False Dim NewBook As Excel.WorkBook Dim ws As Excel.Worksheet Set NewBook = xlApp.Workbooks.Add() With NewBook .Title = "SomeData"...

VBA - do not grab header in range

excel,vba,excel-vba
I have code that looks for the header "CUTTING TOOL" using a .Find method. It loops through multiple files and multiple worksheets in the opening files. I have run into the problem that when it goes through multiple worksheets in one open file and the column is empty under the...

GetWindowsDirectory() API returns wrong (vba\vb6)

vba,winapi,vb6
on my Windows-Terminal user, I'm trying to have two application point to the same Windows directory, one written in VBA one in VB6. When calling the GetWindowsDirectory() API from VB6 it returns the correct path C:\documents and settings\%user%\Windows When calling it from VBA macro, it returns C:\Windows Notice that same...

MS Access VBA: UBound & LBound functions returning subscript out of range error on class array

vba,access-vba
I am receiving a "Subscript out of range" error when calling the LBound() and UBound() functions on a global object's array in MS Access 2003 VBA. I don't understand why this is occurring because I am certain the array has been initialized since I can access values from the array...

Extract text which begin with the same two characters and end in a numeric character

regex,vba,excel-vba,user-defined-functions,udf
I would like to extract a code from a larger extract of text, the constants I have is the Code will either start with WP or MD and end in a Numeric value and example of the patterns the code can be in are below; WP0053 WP053 WP_053 WP_0053 WP...

Format Excel worksheets using for each loop VBA

vba,foreach
I have a workbook with 3 sheets. I would like to format each sheet the same using VBA (set font size, auto fit columns, sort). I found a piece of code to loop through the sheets: Sub wsLoop() ' Declare Current as a worksheet object variable. Dim ws As Worksheet...

Excel VBA - ShowAllData fail - Need to know if there is a filter

excel,vba,excel-vba,filter
I have automated a proper record input into the table that I use as a database, and when the table is filtered the input don't work. So I have code this to unfilter DataBase before every record input. Public Sub UnFilter_DB() Dim ActiveS As String, CurrScreenUpdate As Boolean CurrScreenUpdate =...

Removing Alert When Using DeleteFile API

vb.net,vba,api,delete
I'm writing a VBA application which involves looping a large number of directories recursively. I am using the FindFirstFile API to to achieve this, as it offers a substantial performance boost over the FileSystemObject. In order to remove the FSO from my code entirely, I need a routine to delete...

How do I get a cell's position within a range?

excel,vba,excel-vba
How would I go about getting the relative position of a cell within a range? Finding the position of a cell in a worksheet is trivial, using the Row- and Column-properties, but I am unsure of how to do the same within a range. I considered using the position of...

Type Mismatch Error in DLOOKUP Function

excel,vba
I am getting Type mismatch erro in below code where unit,primepro and subpro datatypes are given as 'TEXT' Private Sub Status_AfterUpdate() If (Me.Status.Value = "COMPLETED") Then Me.Combo35.Value = DLookup("Unit", "Units", "PrimePro='" & Me.Combo33.Value & "' And "SubPro='" & Me.Subact.Value & "'") End If End Sub Please help....

VBA how to initialize vCPath

vba,excel-vba,excel-2010
How do I initialize vCPath? VBA Run-Time Error 1004 @Garry's Student says I "must somehow use the info you get from Application.FileDialog(msoFileDialogOpen) to generate the full filespec of the file you wish to open". What's the simplest way to do this? I am a VBA beginner: I have been programming...

If cell value starts with a specific set of numbers, replace data

excel,vba,excel-vba
My cell values are strings of numbers (always greater than 5 numbers in a cell, ie 67391853214, etc.) If a cell starts with three specific numbers (ie 673 in a cell value 67391853214) I want the data in the cell to be replaced with a different value (if 673 are...

Excel VBA User-Defined Function: Get Cell in Sheet Function was Called In

excel,vba,excel-vba,user-defined-functions
I have a user-defined function in Excel that I run in multiple sheets. I am trying to use Cells(i, j) to pull the value of cells by their row and column in the sheet in which my function is called. Instead, Cells(i, j) pulls the value of cell [i,j] in...

Exit Sub And Call another Sub

vba,excel-vba,call
I have two subs, sub1 and sub2. I want to exit sub1 completely and start sub2 if a condition is satisfied. My attempt is (running from : sub1 . . If x=y Then Exit Sub And Call sub2 End If . . End Sub ...

Copying a Range from Excel and Pasting it into Powerpoint NOT as a metafile but as a table which you can edit in PPP

vba,excel-vba,powerpoint-vba
All I want to do is copy a range from Excel and then paste this range into PowerPoint. When my range is manually copied from Excel to the clipboard... If I right click on a blank slide when pasting into PowerPoint, it gives me the option to paste "using destination...

Excel Search VBA macro

excel,vba,excel-vba
I have been given the task of searching through a large volume of data. The data is presented identically across around 50 worksheets. I need a macro which searches through all these sheets for specific values then copies certain cells to a table created in a new workbook. The macro...

Get the VBProject of a Database

vba,ms-access,access-vba,vbe
Given a database object in MS Access VBA, how can one get that database's VBProject? Function GetVBProject(ByVal db As Database) As VBProject Set GetVBProject = ??? End Function The only way I know how to get VBProjects in Access is through Application.VBE.VBProjects.Item(???). However, I won't know what order of the...

INDEX MATCH VBA (return a value based on two criteria)

excel,vba,excel-vba,lookup,formulas
I'm doing some work for a client where they receive a weekly report of customers and regions (two columns, A for Customer & B for Region, in a worksheet). * I've omitted the other columns in this spreadsheet for the sake of clarity They need to match the price on...

Verify If New Record Access 2010

vba,ms-access
I have a table created to hold all my client data. The data is all entered in via form. When a new record is created (new client added) I also need to create an opening transaction balance on a separate table. So what is the best way to... 1) Identify...

VBA Macro to convert OLE to text results in “Word has encountered a prob.” error

vba,popup,word-vba
I am using the following VBA script to parse through a word document and open every OLE table object, copy the table, and paste back into word so that the data in the tables can be searchable. However, after the script runs for a while, Word gives me an error...

Excel VBA Program Code by Using Randomize Timer

vba
What is wrong in below program code, why not returning correct result. Whenever i put any number in excel cell (1,1) and run the program, Numbers changed automatically, also not throwing a correct result in cell (1,2). Please Help as i learning VBA. Private Sub Sheet2_1() Dim num1 As Integer...

How to create a date using strings in vba?

vba,ms-access,access-vba,ms-access-2003
I want to run a for-loop from sometime to some specific time. Let's say from the first day of the year to the last day: I am given the year and I need to add the month and the day to it: I am trying to concatenate into a full...

VBA - printing empty cells

excel,vba,excel-vba
I have code that takes information from under two specific column headers in opening files and prints them to a masterfile. One column is empty every few files and I need it to print empty cells to column 2 of my masterfile in the range of the filled cells of...

excel search engine using vba and filters?

excel,vba
I am using the following vba code to filter my rows in excel based on the value in my cell C5 Sub DateFilter() 'hide dialogs Application.ScreenUpdating = False 'filter for records that have June 11, 2012 in column 3 ActiveSheet.Range("C10:AS30").AutoFilter Field:=1, Criteria1:="*" & ActiveSheet.Range("C5").Value & "*" Application.ScreenUpdating = True End...

Concatenate N number of columns between 2 specific column name in VBA Excel

excel,vba,excel-vba
I am trying to concatenate the selected range between 2 specific columns. My first column name is "Product-name" (First column is fixed) and second specific column is not fixed. It can be 3rd, 4th, 5th or N. The name of that column is "Price". I want to concatenate all columns...

EXCEL VBA: How to manupulate next cell's (same row) value if cell.value=“WORD” in a range

excel,vba,excel-vba
I want to change the next cell in same row in a if cell.value="word" in a range. I have defined the range, using 'for' loop. In my code, if cell.value="FOUND THE CELL" then cell.value+1="changed the next right side cell" cell.value+2="changed the second right side cell" end if I know this...

Simple VBA Select Case statement not working, Why not?

vba,switch-statement,case
Simple Select Case statement is not working as expected. Message should show this as falling into the "too long" bucket but it comes up as "too short" Lenn = 20 Select Case Lenn Case 7 msg = "You've entered " & Lenn & " digits, this is ok" Case 11...

Sort multiple columns of Excel in VBA given the top-left and lowest-right cell

excel,vba,excel-vba,sorting
I am trying to sort these three columns (Sort By Col-2) in excel using VBA. Top-left (Row number and Column number e.g. 1,1) and lowest-right cell (Row number and Column number e.g. 9,3) are known. Every cell contains the values of String type. Input: Col-1 Col-2 Col-3 P1 I1 XYZ...

read variable excel data into variant with the same format

excel,vba,excel-vba,variables,data-structures
I'm currently writing a Macro for Excel. First I want to read my variable settings from row 20 from my sheet "Filter" into my variable "test": ' Define Last Column with a value LastCol = Sheets("Filter").Cells(20, Sheets("Filter").Columns.Count).End(xlToLeft).Column Col_Letter = Split(Cells(1, LastCol).Address(True, False), "$")(0) ' Read Data into variable test =...

Excel 2010 VBA Can't get Sub Menus to display

vba,excel-vba,excel-2010,submenu
I have the following code that builds a custom menu in Excel. Works well. I'm trying to modify it to use sub menus. It will add the menu item for East Options and West Options. I'm trying to modify the East and West # 1 items so they appear as...

PowerPoint VBA Macro Gives Run Time Error 448: Named argument not found

vba,powerpoint,powerpoint-vba
I'm trying to create a PowerPoint 2010 VBA Macro to add a text box to every slide. However, using the command from the MSOffice documentation to create a text box doesn't even work. Set myDocument = ActivePresentation.Slides(1) myDocument.Shapes.AddTextbox(Type:=msoTextOrientationHorizontal, _ Left:=100, Top:=100, Width:=200, Height:=50).TextFrame _ .TextRange.Text = "Test Box" This returns...

Label linked to a text box value

excel,vba,textbox,label
Good morning, I am editing an User Form on VBA Excel and I would like to show an alert if the user insert a certain value in a text box. I wrote this code: If txtbox.Value < 0 Then lbl_Alert.Visible= True Else lbl_alert.Visible=False End IF The code works properly but...

ADODB Connection is empty, Unable to read CSV file

sql,vba,connection-string,adodb,recordset
I have gotten the code below working with all file types except CSV Files. I am trying to copy a CSV file into a worksheet and I have gotten myself confused. All help will be appreciated. The debugger shows: rsConn = "" szSQL = "SELECT * FROM export.csv" When I...

Userform is not unloading once command button is pressed

vba,excel-vba
Having a little trouble with my userform, its not unloading once i hit the command button the data is inputted to the sheet but the userform is not refreshed and the data stays in the text boxes. It was working fine until i put the data validation in, but i...

Find column with unique values move to the first column and sort worksheets

excel,vba,excel-vba,sorting
I have 2 worksheets with the same headers in different orders. Headers are I.D, Name, Department, Sales, Start date, End Date and a few others. What I am aiming to do is search through the workbooks in which the headers may be in different orders, find the column which has...