excel-vba

Excel tab sheet names vs. Visual Basic sheet names

It seems that Visual Basic can not reference sheets according to user-modified sheet names. The worksheet tabs can have their names changed, but it seems that Visual Basic still thinks of the worksheet names as Sheet1, etc., despite the workbook tab having been changed to something useful. I have this: TABname = rng.Worksheet.Name '...

VBA Excel macro: use Range to act on a different worksheet

I am very much a beginner when it comes to VBA programming. I have a Macro that hides or shows columns based on the value in one cell: Sub HideColumnsMacro() Range("b8:o8").EntireColumn.Hidden = False v1 = Range("b2").Value + 1 If v1 < 12 Then With Range("b8") Range(.Offset(0,v1), .Offset(0, 12)).EntireColumn.Hidden = True En...

Copy recordset data into multiple sheets to avoid problem of maximum rows limit in Excel VBA

I am developing reporting application in Excel/vba 2003. VBA code sends search query to database and gets the data through recordset. It will then be copied to one of excel sheet. The retrieved data looks like as shown below. ProductID--------|---DateProcessed---------|----State----- 1................|.. 1/1/2010..............|.....P...

Converting big-endian into little-endian and vice-versa in VBA

My machine is little-endian (Intel byte order). I need to read a binary file containing 16-bit signed integer data in Motorola/IEEE byte order ("big-endian"), then do some calculations, and finally write the resulting integer data in a big-endian binary file. How do I do the above in VBA, i.e. convert big-endian into little-endian and ...

Integer Overflow in VBA project

Hi, everyone. Here is a small VBA (Excel) function that i wrote, full of MsgBoxes for debugging. I am passing in the numbers 10 and 1 as arguments, and getting an overflow error when the program reaches the top of the For loop, before it begins the first iteration. Any thoughts are appreciated. Declare Sub Sleep Lib "kernel32" (ByVal...

Excel formula question

I'm trying to convert an excel formula that I found to a more easily understood formula. Below is the formula I'm trying to interpret. What is ei?? =3*ei/2-27*ei^3/32 ...

Create new recordset by executing query on another recordset in Excel VBA

I am using Excel VBA 2003. Is it possible to create new recordset by executing query on another recordset ? The query could look like "select * from recordset1 where " Thanks, ...

Populating Specific Cells Using VBA

I am using VBA to pull from a SQL table and it automatically populates cell E14. Not sure why it's that cell, but is there a way to specify which cell it pulls the data into? Here's what I have right now: strSQL = "SELECT distinct Source FROM dbo.Simulations WHERE SimulationID = 5 ...

VBA to C# - Porting Userforms to Winforms?

I am porting a Excel-VBA based app which uses Userforms over to a C# Winforms application. How do I convert the Height and Width of the VBA-Userform to the same screen dimensions in the C#-Winforms application? Is there a ratio that can use be used? Currently the VBA-Userform has a dimension of 179.25 W x 245.25 H which is optimized f...

Unable to diligently close the excel process running in memory

I have developed a VB.Net code for retrieving data from excel file .I load this data in one form and update it back in excel after making necessary modifications in data. This complete flow works fine but most of the times I have observed that even if I close the form; the already loaded excel process does not get closed properly. I tri...

Export sheet from Excel to CSV

I am creating a spread sheet to help ease the entry of data into one of our systems. They are entering inventory items into this spread sheet to calculate the unit cost of the item (item cost + tax + S&H). The software we purchased cannot do this. Aan invoice can have one or more lines (duh!) and I calculate the final unit cost. This is...

What is the maximum number of controls that a VBA form can hold?

I'm currently building an Excel 2003 app that requires a horribly complex form and am worried about limitations on the number of controls. It currently has 154 controls (counted using Me.Controls.Count - this should be accurate, right?) but is probably only about a third complete. The workflow really fits a single form, but I guess I c...

How to fill in Different String Values in Different Cells in Excel 2007 VBA marcos

Hello everyone, So I am trying to fill in Values "A-Z, 0-9" in a 2007 excel macro in four different locations (I am trying to put A-Z and 0-9 in cells: a1 to d9, e1 to h9, a10 to d18, and e10 to h18). So far I have the code: Sub TwoDArrays() Dim Matrix(9, 4) As Variant Dim Matrix2(9, 4) As Variant Dim Matrix3(9, 4) As Variant Dim Mat...

Excel macro to change external data query connections - e.g. point from one database to another

I'm looking for a macro/vbs to update all the external data query connections to point at a different server or database. This is a pain to do manually and in versions of Excel before 2007 it sometimes seems impossible to do manually. Anyone have a sample? I see there are different types of connections 'OLEDB' and 'ODBC', so I guess I n...

Excel macro to change location of .cub files used by pivot tables? (to allow .xls files that depend on .cub files to be moved)

I often use Excel with pivot tables based on .cub files for OLAP-type analysis. This is great except when you want to move the xls and you realise internally it's got a non-relative reference to the location of the .cub file. How can we cope with this - ie make it convenient to move around xls files that depend on .cub files? The best ...

How do you scale a pictureLink object in Excel 2010

In Excel 2007 it is possible to scale a pictureLink object (created with the Camera Tool) using the following VBA code. With ActiveWorkbook.Sheets(sht).Pictures(name) .ShapeRange.ScaleWidth scaleValue, msoTrue .ShapeRange.ScaleHeight scaleValue, msoTrue .top = top .left = left End With This code places the picture corr...

VBA Tab Key putting actual Tab Value in Text Box instead of navigating to next control

I have a VBA form (in Excel if that matters) that contains text boxes. On three occasions, I have found myself pressing the tab key to navigate to the next control, but instead an actual TAB is being put in the text box. The form normally acts as it should, but it does concern me that this gremlin is showing up sporadically. It has sh...

Inserting Rows Without Selecting Anything?

Hello SO, I'm working in VBA and want to insert a row in a specific location without selecting it. The issue I'm having is that after the row is selected, the spreadsheet is scrolled down to that row when the script is finished running. I want to be able to do this without the spreadsheet being scrolled down to the inserted row. Row...

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 in Sub or Function" Do you know what I did wrong? I tried to use Global instead of Public, but got the same problem. I tried to declare ...

Visual Basic: passing arrays between Functions???

I have a visual basic function with a ParamArray output, and I want that output to be available to another function, without having to put it on a worksheet just to pick it into that second function. Is there a way to transfer arrays between functions in visual basic? Thanks in advance for your response. ...