Tagged Questions
46
votes
4answers
12k views
Excel macro - Avoiding using Select
I've heard much about the understandable abhors of using .Select in Excel VBA Macros, but am unsure of how to avoid using them, or a good resource that can shed some light on how to avoid it.
I've ...
6
votes
2answers
4k views
MS Excel crashes when vba code runs
I am having a problem with excel crashing when i run VBA code on an excel sheet.
I have some code to add a formula to a range of cells as follows:
Private Sub Worksheet_Change(ByVal Target As Range)
...
4
votes
2answers
10k views
Last not empty cell in row; Excel VBA
I have an excel sheet in which I need to find the last non empty cell in a specific column.
How do I do this?
The below will select this for me, but it will select the first not empty cell, I need ...
29
votes
2answers
90k views
Loop through files in a folder using VBA?
I would like to loop through the files of a directory using vba in Excel 2010.
In the loop, I will need
the filename, and
the date at which the file was formatted.
I have coded the following ...
29
votes
2answers
43k views
How to add a custom Ribbon tab using VBA?
I am looking for a way to add a custom tab in the Excel ribbon which would carry a few buttons. I chanced on some resources addressing it via Google but all look dodgy and outrageously complicated.
...
11
votes
7answers
44k views
Detect whether Excel workbook is already open (using VBA)
I have opened a file of MS Excel named as "myWork.XL" through coding. Now I want a syntax of coding that can tell me about its status whether it is opened or not. In other words if I open the same ...
5
votes
5answers
16k views
Formatting MM/DD/YYYY dates in textbox in VBA
I'm looking for a way to automatically format the date in a VBA text box to a MM/DD/YYYY format, and I want it to format as the user is typing it in. For instance, once the user types in the second ...
7
votes
2answers
2k views
How to use the Implements in Excel VBA
I'm trying to implement some shapes for an engineering project and abstract it out for some common functions so that I can have a generalized program.
What I'm trying to do is have an interface ...
-1
votes
3answers
1k views
How to compare two entire rows in a sheet
I am new to VBA. I have job in my hand to improve performance of VBA code. To improve performance of the code, I have to read entire row and compare it with another row. Is there any way to do this in ...
10
votes
2answers
5k views
Pop up the Excel Statusbar?
I'm developing an application for excel that takes a long time to run so it would be nice to have a progress bar pop up and give some indication of the progress. I was looking at the Statusbar ...
5
votes
2answers
6k views
ExecuteExcel4Macro to get value from closed workbook
OK I found this bit of code and thought it might be good to use, if I just need to pull one value from a closed sheet.
strInfoCell = "'" & strPath & "[" & strFile & "]Sheet1'!R3C3"
...
12
votes
1answer
48k views
Excel column number from column name
How to get the column number from column name in excel using excel macro
5
votes
2answers
5k views
Unprotect VBProject from VB code
How can i unprotect my VB project from a vb macro ?
i have found this code:
Sub UnprotectVBProject(ByRef WB As Workbook, ByVal Password As String)
Dim VBProj As Object
Set VBProj = ...
5
votes
5answers
9k views
Efficient way to delete entire row if cell doesn't contain '@'
I'm creating a fast sub to do a validity check for emails. I want to delete entire rows of contact data that do not contain a '@' in the 'E' Column. I used the below macro, but it operates too ...
5
votes
5answers
54k views
Copy data from another Workbook through VBA
Guys here's what I want to do and I have a little trouble doing it.
I have 1 Workbook where I want to collect data from different files doing something like this.
Do While ...
8
votes
5answers
54k views
VBA Macro On Timer style to run code every set number of seconds, i.e. 120 seconds
I have a need to run a piece of code every 120 seconds. I am looking for an easy way to do this in VBA. I know that it would be possible to get the timer value from the Auto_Open event to prevent ...
4
votes
2answers
5k views
VBA macro to mass update multiple files in same location
Very new to this so please help. Im trying to mass update files in a static folder location, many files in one folder.
What i want to do is
run VBA macro in Excel 2010 to goto a network location ...
1
vote
2answers
9k views
Import web data in excel using VBA
I want to import MutualFundsPortfolioValues to Excel. I don't know how to import data from a web site which I need to do is import web data to Excel within 2 different dates of chosen companies ..
...
3
votes
1answer
78 views
How to use Regular Expressions (Regex) in Microsoft Excel both in-cell and loops
How can I use regular expressions in Excel and take advantage of Excel's powerful grid like setup for data manipulation?
In-cell function to return matched pattern or replaced value in string.
Sub ...
0
votes
1answer
9k views
Copy column from one Excel sheet to another Excel sheet [closed]
I want to copy particular columns from one Excel sheet to another Excel sheet in a different workbook. How can I use a macro to copy some columns to different Excel sheet?
4
votes
5answers
16k views
What is the best way to master VBA macros for MS Office applications? [closed]
I am working in a farm that requires me to do lots of MS Office application work. I want to automate all these tasks using VBA macros. So, I want to master the skill sets to write VBA macros for MS ...
17
votes
2answers
9k views
Multi-threading in VBA
Does anybody here know how to get VBA to run multiple threads? I am using Excel.
9
votes
5answers
62k views
Accessing SQL Database in Excel-VBA
I am copying an VBA code snippet from MSDN that shows me how to grab results from a SQL query into excel sheet (Excel 2007):
Sub GetDataFromADO()
'Declare variables'
Set objMyConn = New ...
12
votes
5answers
8k views
Can VBA Reach Across Instances of Excel?
Can an Excel VBA macro, running in one instance of Excel, access the workbooks of another running instance of Excel? For example, I would like to create a list of all workbooks that are open in any ...
7
votes
7answers
29k views
Want VBA in excel to read very large CSV and create output file of a small subset of the CSV
I have a csv file of 1.2 million records of text. The alphanumeric fields are wrapped in quotation marks, the date/time or numeric fields are not.
For example
"Fred","Smith",01/07/1967,2,"7, The ...
5
votes
4answers
70k views
Read/Parse text file line by line in VBA
I'm trying to parse a text document using VBA and return the path given in the text file.
For example, the text file would look like:
*Blah blah instructions
*Blah blah instructions on line 2
...
1
vote
2answers
264 views
Can I make this macro more efficient or faster?
I am brand new to coding. This macro runs slow and I'm hopeful that someone can help me clean it up. Thanks in advance for your help.
I developed the code to update my company's "Call Router" ...
20
votes
4answers
122k views
automatically execute an Excel macro on a cell change
How can I automatically execute an Excel macro each time a value in a particular cell changes?
Right now, my working code is:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not ...
6
votes
2answers
11k views
Download attachment from Outlook and Open in Excel
I'm trying to download and then open an Excel spreadsheet attachment in an Outlook email using VBA in Excel.
How can I:
Download the one and only attachment from the first email (the newest email) ...
8
votes
2answers
18k views
Assign code to a button created dynamically using VBA on excel
I'm trying to get a button I've created dynamically on an excel userform form to run a macro called "transfer" which I've written in Module 1 of the "Modules" section of my project.
Below I've pasted ...
8
votes
3answers
34k views
Sending formatted Lotus Notes rich text email from Excel VBA
I have little Lotus Script or Notes/Domino knowledge but I have a procedure, copied from somewhere a long time ago, that allows me to email through Notes from VBA. I normally only use this for ...
14
votes
7answers
73k views
Way to run Excel macros from command line or batch file?
I have an Excel VBA macro which I need to run when accessing the file from a batch file, but not every time I open it (hence not using the open file event). Is there a way to run the macro from the ...
14
votes
3answers
42k views
How to add a reference programmatically vba-Excel
I can't seem to figure out how to add a reference programmatically to Excel 2007 using vba.
I know how to do it manually Open VBE --> Tools --> References --> browse --_> File Location and Name. But ...
10
votes
8answers
2k views
Is it possible to fill an array with row numbers which match a certain criteria in Excel VBA without looping through them?
I would like to fill an array in vba with the row numbers of only rows which meet a certain criteria. I would like the fastest method possible (for example, something like RowArray = ...
11
votes
5answers
38k views
vba: get unique values from array
is there built in functionality in vba to get unique values from a one-dimensional array? what about just getting rid of duplicates?
if not, then how would i get the unique values from an array?
6
votes
1answer
8k views
VBA inheritance, analog of super
For example I have class A which implements class B
---class A----
implements B
public sub B_do()
end sub
--class B----
public sub do()
end sub
How can I call do() from A? (super.do()) So, how ...
16
votes
4answers
198k views
How do I declare a global variable in VBA?
I wrote the following code:
Function find_results_idle()
Public iRaw As Integer
Public iColumn As Integer
iRaw = 1
iColumn = 1
And I get the error message:
"invalid attribute ...
1
vote
1answer
7k views
Selecting columns that have values in Excel Macro (range object in VBA)
How do I modify this line in VBA to only select the columns that have values?
Set rng = Range("A1", Range("A65536").End(xlUp)).SpecialCells(xlCellTypeVisible)
I don't think I'm doing something ...
20
votes
4answers
68k views
How to protect cells in Excel but allow these to be modified by VBA script
I am using Excel where certain fields are allowed for user input and other cells are to be protected. I have used Tools Protect sheet, however after doing this I am not able to change the values in ...
11
votes
5answers
69k views
Read lines from a text file but skip the first two lines
I've got this macro code in Microsoft Office Word 2003 which reads the lines of a text file. The lines each represent a string value that I need to use later in the code.
However, the first two lines ...
6
votes
2answers
7k views
Dir() function not working in Mac Excel 2011 VBA
Hi I am trying to list all the files in a subdirectory of where the Excel workbook is residing in. For some reason, the code cannot execute beyond the Dir function. Can anyone please advise? Thank ...
13
votes
1answer
2k views
Accessing a VSTO application-addin types from VBA (Excel)
We have a VSTO application-addin (not a document-addin) for Excel, and we want to expose an event to VBA code so that the VBA macro can do some action when this event fires in the addin. How can I ...
6
votes
2answers
8k views
Handle JSON Object in XMLHttp response in Excel VBA Code
I am need of handling JSON Object which is the response of XMLHTTPRequest in Excel VBA. I wrote below code but not succeeded. Please guide me.
Dim sc As Object
Set sc = ...
2
votes
1answer
2k views
Copy last column with data on specified row to the next blank column
I have a spread sheet and I need to look for the last column that has data in it. Then I need to copy this column and copy it to the next blank column.
Is there a way to do this?
I've managed to do ...
1
vote
3answers
91 views
Seaching an excel with two search words using vba macro [closed]
I am using vba macros.
Task:
1) User will give two inputs viz. number of devices sold (column B) and week number (column A).
2) Search the excel file using these two and get the earnings.
...
1
vote
2answers
9k views
Reading Web Pages using Excel VBA
I want to read web pages using Excel VBA. How do I carry out this task? Is it even possible?
8
votes
7answers
27k views
How do I get the old value of a changed cell in Excel VBA?
I'm detecting changes in the values of certain cells in an Excel spreadsheet like this...
Private Sub Worksheet_Change(ByVal Target As Range)
Dim cell As Range
Dim old_value As String
Dim new_value ...
2
votes
5answers
2k views
VBA Error “Bubble Up”
I haven't read much about it, but the author at the link below recommends that I don't use "bubble up" to centralize error handling in VBA.
Excel Programming Weekend Crash Course via Google Books
...
1
vote
1answer
227 views
Need help making the VBA Excel code better
I need help improving my code below as it is a total mess. The correction is just a stop gap for something much bigger that I am trying to achieve. In short what I want to do is to create a pivot like ...
0
votes
1answer
58 views
If Not function proceeds when value *is* the one specified
I am trying to write a script which checks for duplicate values in another worksheet, but I cannot get it to work. At line problem the If function always proceeds, whether set to If Not or If. ...