Excel 2010 :: Condensing VBA Code - Using Dynamic Variables?

Jul 17, 2012

I have some VBA that dumps various sheets data into an SQL Database.

Part of that requires me to sanitize all of the fields before they make it to the DB, (at least to prevent the code from breaking itself w/ errant ' characters.

right now my code is as follows

Code:
If InStr(aa, "'") > 0 Then
aa = Replace(aa, "'", "''")
End If
If InStr(bb, "'") > 0 Then
bb = Replace(bb, "'", "''")

[Code] ......

I was hoping to condense it to something like the following, however it is not working how I hoped / want it to. .. I had found somewhere out there that this Eval() function possibly could be used to 'reference' dynamic variables, however it does not appear to work at all anymore, and even then it may only have worked to 'read' and not 'write' to the variable. (Excel 2010, on Windows 7 64-bit).

Code:
itemsToSanitize = "aa,bb,cc,dd,ee,ff,gg,hh,ii,jj,kk,ll,mm,nn,oo,pp,qq,rr,ss,tt,uu,vv,ww,xx,yy,zz,aaa,bbb,ccc,ddd,eee,fff,ggg,hhh"
ITSArray = Split(itemsToSanitize, ",")

For Each thing In ITSArray
If InStr(Eval(thing), "'") > 0 Then
Eval(thing) = Replace(Eval(thing), "'", "''")
End If
Next thing

View 7 Replies


ADVERTISEMENT

Excel 2010 :: Condensing Dim Statement

May 7, 2013

Windows 8, Excel 2010,

What is a condensed way of saying;

Dim x As Integer
Dim y As Integer
Dim z1 As Integer
Dim z2 As Integer
Dim z3 As Integer
Dim z4 As Integer
Dim AA As Integer

View 9 Replies View Related

Dynamic Assignment Of Value To Variables Using Macros And VBA Code

Jul 6, 2012

I have two columns one with the variables names and the other with the values now I have to assign vales to teh variables dynamically using the macros and vba code.

View 7 Replies View Related

Excel 2010 :: SUMIF With Multiple Variables?

Dec 9, 2013

Excel 2010 Windows 7

There is a lot going on, including a check box, which I dont have much experience with and data on two different sheets. I need to sumif the box is checked (true cell) and the item matches the item on another sheet then I need to sum the qty in the adjacent column.

Inventory sheet:

I will have a similar formula in both C and D, but this will be for what I need in D, and I should be able to figure C out from that. What I have to get my starting number is "=SUM('Proc-Pack SUMMARY'!B16-'Proc-Pack SUMMARY'!C16)". Now I need to subtract what is sold from that number to give me a current on hand number.

Type
date
qty packaged
qty bulk

Inventory sold sheet:

The type column is a drop down box with that matches the type column on the inv sheet. The "cyl" and "lbs" columns have check boxes in them. So if C (cyl) is checked and A matches A on the inventory sheet I need to subtract D.

Type
Cyl
Lbs
Qty

Ive tried various variations of this "=SUM('Proc-Pack SUMMARY'!B16-'Proc-Pack SUMMARY'!C16)-sumif(Sold!F:F,"true",Sold!E:E=Inventory!A:A,Sold!H)"

Also is it possible to link so you can only one of the two check boxes in a row? I know the option button does this, but I didnt think that would work with the formula.

View 7 Replies View Related

Excel 2010 :: Overflow Error 6 - When All Variables Defined As Integers

Jul 17, 2012

I have tracked down an overflow Error 6 to the following line:

dMax = Int(s * DPoints / SPoints)

Where all variables are defined as Integers. The error goes away when I define s as Long, but I don't understand why this should be required since none of the individual variables ever exceed the scope of an Integer (-32768 to 32767).

Strangely, I get the same overflow problem when I type either of the following calculations in the immediate window:

? Int(328 * 100 / 1000)
? 328 * 100 / 1000
? 328 * 100

Note that no variables are defined, so why the overflow problem? Surely Excel/VBA should be able to work with this very basic calculation without any problem, by assigning the appropriate dimension, no?

Is this a known problem with Excel/VBA?

I am using Windows 7, with Excel 2010 (updated from 2009).

View 9 Replies View Related

Excel 2010 :: Public Variables From Event Handling Procedure?

Jan 22, 2014

Excel 2010

I am trying to set public variables from an event handling procedure based in a worksheet so I can use that variable in a userform. Nothing I have tried works no matter where I declare the variable. I am using a msgbox to display the variable (a range) but it shows as blank regardless of whether I place the variable in a module, this workbook object or in the sheet object where the event code is placed.

I am sure there is a simple way to transfer variables from the sheet's code (where it must remain as the variable depends on the target cell's position that triggers the event).

View 2 Replies View Related

Excel 2010 :: VBA Repeating Formula(s) In Specified Cells Based On Defined Variables?

Dec 28, 2012

In my worksheet, I know the last line of my report AND I know how many "reporting segments" (all equidistant and identical) there are in the report based on the last row using the below (which I tested in several reports in messages):

VB:
Dim vListEnd As Variant
Dim vTaskCount As Double
vListEnd = ActiveSheet.Range("A1").Offset(Sheet1.Rows.Count - 1, 0).End(xlUp).Row
vTaskCount = ((vListEnd - 5) / 22)

My "reporting segments" are ALWAYS 22 rows each and the first one always starts in row 5. Example: A document where the last row (containing an End of Report special character) is 247 would have 11 reporting segments.

Within each reporting segment, there are two different formulas needed.

For the first reporting segment located in rows A5 thru J27:

I need FORMULA1 in all cells of the range (D5:D15 dragged out to H5:H10(not 15) and D18) and FORMULA2 in cells (F20:F22,J20:J22).

Then I need to repeat that vTaskCount number of times (number of segments) and at intervals of 22 (segment repeater offset). Some reports may have 2 segments, some might have 50, but the structure is always identical.

My formulas are all pretty simple if it makes a difference (originally using FormulaR1C1 = "=RC[-1]+RC[-3]" --- but because I now know solid cell locations I suppose I don't need to make them relative, too.)

View 2 Replies View Related

Excel 2010 :: Dynamic Line Chart

Jul 12, 2012

I would like to plot the 1st dynamic line chart as shown in [URL] ..... but i never write any excel macro 2010 before, any sample of this?

View 4 Replies View Related

Excel 2010 :: Pivot Dynamic Name Range?

Jan 27, 2013

I am trying to insert a Pivot table with dynamic Name Ranges. It needs to start from Cell B1 as Column A has hidden formulas in them. I created an Dynamic Name range and tried to insert a pivot table. Excel then throws out a error stating "Data source reference is not valid". I tried re-saving the document but still no luck.

View 1 Replies View Related

Excel 2010 :: VBA - Open Sheet With Dynamic Name?

Nov 25, 2013

I have this workbook in which each sheet refers to a month in a specific year (e.g. Jan12, Nov13), plus an "overall" sheet where I would like to, among other stuff, create a button that would lead me to the sheet refering to "today's month".

Although I know how to create a "static" macro that leads me to a particular sheet, I don't know how to create one in which the sheet it refers to is changing every single month.

(Note: I'm using Win7, MSExcel 2010)

View 6 Replies View Related

Excel 2010 :: Dynamic Dropdown List Of Dates?

Aug 9, 2013

I'm trying to create a set of three dynamic/dependent drop down lists of date values, based on a set of imported data. Depending on whether the preferred choice is to list all dates in a range or just dates on the 15th, the available start and end drop down lists will change.

In addition, if possible I would then like to display a list of valid dates (not sure if this needs to be VBA).

The attached sheet shows/explains what I am attempting but here it is as well:

If B3 is set to show all dates in the month then:

the first dropdown option for C3 will be the first date of IMPORT (D2)
the first dropdown option for C4 will be the C3 value, to the last date in IMPORT (D) column

If B3 is set to show 15th of the month then:

the dropdown for C3 will be the first date of IMPORT (D) column with a date of 15th the dropdown for C4 will be in the range of C3 to the last date of IMPORT (D) column with a date of 15th only dates of 15th will be listed in both C3 and C4 dropdownlists

General

the dates in IMPORT column D are taken from IMPORT column A, B & C, which will be imported and will always be date sequential the number of rows of date entries will change with every import but there will never be any blank rows between dates the values in IMPORT columns A, B & C will always be numerical, and can be referenced if required [ideally] the LIST OF DATES will be populated with the date range, based on the option selected in B3

I'm fairly familiar with Excel (2010) and I have also done some VBA but I'm new to dynamic, nested dropdown lists and I'm unsure what the most practical way is to achieve this.

View 1 Replies View Related

Excel 2010 :: Dynamic Range Not Working Properly

Jan 8, 2013

Had been using this formula for almost 3 years, recently the formula didn't work properly as the range goes down halfway only instead of to the last data in the column. I'm using Excel 2010 now.

=Sheet1!$A$2:INDEX(Sheet1!$A:$A,COUNTA(Sheet1!$A:$A))

View 2 Replies View Related

Excel 2010 :: Dynamic Range In The Middle Of Worksheet

Oct 27, 2013

how to use the offset function to create a dynamic range in Excel 2010. An in-house Excel form I work with spans columns A thru P and has three sections. In Section 2 the user fills in employees who are requesting to work overtime. Section 2 starts row 12 and ends row 61. It's sometimes necessary to add rows to this section. How do I make this section/range dynamic using the offset function?

View 1 Replies View Related

Excel 2010 :: VBA Code To Extract HTML Source Code Not Working On Google Sites

Dec 6, 2012

I have previously used the following code to successfully pull out IE webpage source code for string manipulation.

Its a crude example to demonstrate the principle:

Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Public IE As Object
Sub Sample()
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True

[Code] ......

However when I substitute in a Google websites address into the IE.Navigate command, the code runs to the "Source_Code = IE.document ...." line then flags up a Microsoft Visual Basic error. "Run-time error '438': Object doesn't support this property or method"

The webpage that I am trying to access is a confidential company site, so you won't be able to access it yourself, but starts with [URL] ......

The one thing that I have noticed about this website is the Privacy Report icon in the lower right status window (Picture of an eye with a restricted symbol in front). I don't know whether this is the cause of my problem, or purely an incidental observation.

Is there something peculiar with Google sites that means that the source code cannot be extracted in general, or is this an issue specific to my site ? Does the Privacy Report icon have any relevance, and if so how do I switch that off ?

Using :
MS Excel 2010
IE Explorer 8.0

View 1 Replies View Related

Excel 2010 :: Dynamic Changing Of Series Collection Values?

Jul 6, 2014

I still get the 'Object doesn't support this property or method. Error code 438' error. I am using Excel 2010

VB:
j = 3
Do Until j = 6
ActiveWorkbook.Sheets(k).Activate
Set chartX = ActiveSheet.ChartObjects("X")

[Code]....

The macro is supposed to dynamicaly adjust series range for 3 charts for x,y,z, values in each of sheets. Charts are a line type.

View 3 Replies View Related

Excel 2010 :: Referencing Cells Containing Dynamic Data In Another Worksheet?

Jun 15, 2012

I have a a spreadsheet that pulls user information from our corporate address book. I would then like to copy that data to another worksheet for additional data scrubbing. The problem I am facing is that, I can get the reference to work the first time but if I pull new data down, the destination spreadsheet now shows #REF!

I've tried using the below formulas but they all wind up the same way. ' Results' is the name of the spreadsheet I am making the reference to which has the dynamic data in it.

=Results!#REF!
=INDIRECT("Results!$B3")
=indirect (cell("results",B3)

View 1 Replies View Related

Excel 2010 :: Using Command Button To Insert Row In Dynamic Table?

Aug 30, 2013

I'm using excel 2010 and I need a command button to add rows to the end of the dynamic table.

View 3 Replies View Related

Excel 2010 :: Dynamic Graph Creation Using The Series And Offset Functions?

Jan 7, 2014

I am in the process of setting up some graphs. The graphs will show the last 6 months of data so they move as each month is goes. I saw a slick way of doing this using the count function but this did not quite fulfill my needs. What I was looking for is to be able to input the start month in a cell. The cell would be part of the function within the formula. I created a simplified version of the spreadsheet below.

Spreadsheet.jpg

Then I created my names using the ctrl-F3

Names.jpg

I then created the graph I wanted and wanted to use the formula =SERIES(Sheet1!$B$3,!chtCat,!chtIssuesReported,1). This kept getting an error indicated nothing really. It basically says there is something wrong with my Series function. I have a working version of a similiar worksheet I have been basing my entries on. They look almost identical but mine is failing. I also created a new file and tried this and it still fails. I can run the formula evaluator within Excel 2010 against the !chtCat and !chtIssuesReported names and they both return the correct value (which equals areas on the spreadsheet). I have also tried to enter the spreadsheet name and a tab in front of the names to get them to work and still get an error. Basicall I am trying to create the graph below (this grpah is using the hard coded locations)

Graph.jpg

View 2 Replies View Related

Excel 2010 :: Populate Ranges To Facilitate Dynamic Charts Being Generated

Nov 2, 2013

I'm trying to dynamically populate ranges to facilitate dynamic charts being generated.

I use excel 2010 at work, and 2011 for mac at home.

Dynamic chart ranges populated from named ranges as selected in nested indirectly sourced validation lists

I want any selection made in a dependent validation list which contains a list of named ranges to trigger a worksheet_change event which copies the range the selection points to and pastes it into a dynamic range in another column, beginning as a specified cell.I've tried using this, put together from some code examples from similar, but different issues.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Me.Range("B2")) Is Nothing Then
Range(Range("B2").Value).Copy
Range("P2").Paste
End If
End Sub

Trouble is, I don't really understand this code. It doesn't appear to do anything when I make a worksheet change in "B2", but I don't know exactly what it is. I suspect that perhaps the fact that "B2" is validated from an indirect source might be difficult?

View 8 Replies View Related

Excel 2010 :: Dynamic Range - Cell References Changing In OFFSET Function

Apr 12, 2012

I'm working in Excel 2010. I'm trying to create a dynamic range, using the OFFSET function. I've got it working beautifully but as soon as I save it and close the Name Manager the range stops working. When I go back into Name Manager I find all the cell references have changed (from C1:C600 to C1048572:C595 - or some other strange range).

P.S. What it's doing isn't so important as when the cell references are right it works. But just for full info: It's an OFFSET function, starting at A1. It will look at a list of companies and use a Match function to find out how many rows to offset (based on where the first instance of a particular company. And it uses the COUNTIF to make the range the same number of rows as there are entries for that company.

Here is my broken function:

=OFFSET('Map Point'!A1048572,MATCH("Company Name",'Sheet Name'!C1048572:C595)-COUNTIF('Sheet Name'!C1048572:C595,"Company Name"),0,COUNTIF('Sheet Name'!C1048572:C595,"Company Name"))

View 3 Replies View Related

Excel 2010 :: Making Hard Coded Cell Dynamic While Maintaining Original Content

May 16, 2014

I pulled a set of financial statements from a database into Excel. All of the values are hard coded but I would like to make them dynamic, while maintaining the original content. For example, If cell C3 is a revenue figure for 2012 ($1,000) I would like to link it to cell C5, which will be a currency conversion rate (2.0). So I would like cell C3 to read =1000*C5, which would equal 2000, and for cell D3 to equal 2013 sales*D5, etc. I would also like this to go across a specified range so that I can also change operating expenses, taxes, etc over a number of columns (dates) that I define, all linking to the conversion rate for the given year. Having another tab where you link and anchor is an option but I would prefer something in VBA where I can qickly include this functionality with new workbooks that I download.

I am using Excel 2010.

View 5 Replies View Related

Unzip Code - Works Without Variables, Breaks With Variables...

Feb 5, 2009

Unzip Code - Works without Variables, Breaks with Variables.... This has been driving me bananas...

I have the

View 2 Replies View Related

Excel 2010 :: VBA Code To Open Save As Box In Specified Folder

Apr 24, 2014

I have windows 7 and excel 2010 and am using a macro that opens up a csv file(I think) of daily reports into Excel and then automatically delineates it and formats it how I want it. I will be using this to save a new file every day for the reports from the previous day and want to include at the end of that macro a way to prompt the user to "save as" so that each day they can run the macro and enter in the date and save that report for further use. I am wondering what VBA code I could use at the end of the macro code to prompt the Save As box and if I could already have the save us set up in the following folder... "W:Daily to Fortis Excel2014(the user will put in the date here)".

I've been looking around sites and trying to figure it out. I need the file format to be the same as when you save as "Excel Workbook". I was trying to use the Saveas (filename) function and could get it to save every time as a specific file name in that location but when I run it the next day it has the same name and saves over itself. So I need the user to be able to put in todays date as the filename to create a new one every day.

View 7 Replies View Related

Excel 2010 :: Update Time In A1 Timer VBA Code

Jun 2, 2014

The only change I made was to change the "Sheet1" to "Journal" to match the worksheet name in my workbook.

As you close and reopen the workbook, the timer should start with =NOW() in A1 (formatted as "HH:MM:SS") and count up with the current time until you close the workbook.

I use Excel 2010, could that be the problem, that I copied a VBA code for an older version of Excel???

Question: What exactly is a regular module, do I use Module 1 for the first portion of the code or place it in ThisWorkbook?

AUTO TIME UPDATE VBA

PLACE IN REGULAR MODULE

[Code] ....

View 7 Replies View Related

Excel 2010 :: Macro To Pull AP Within Specific Zip Code?

Jun 15, 2012

I have an excel 2010 spreadsheet that lists all of our vendors and the amount we spent with them over the last year.

I want to know how many of them were local vendors.

I have a list of all the zip codes within a 100 mile radius (there are about 500 zip codes). I would like to write a macro or sort function that searches the entire vendor list and only reports back those vendors that are included in the zip codes I specify.

The columns are as follows:

A B C D E
Vendor City StateZip CodeTotal AP
Vendor 1TROY AL36082527.37
Vendor 2PHOENIXAZ85054100
Vendor 3TUCSONAZ8571416255

I want to keep the all the columns, I just want to eliminate all of the vendors that do not fall within the zip code criteria I set.

View 5 Replies View Related

Excel 2010 :: Macro Or VBA Code To Rearrange Data

Jul 5, 2012

I'm using Excel 2010 and XP. I have data in rows 1 -4 that can not be altered. There are headings in Row 5, B-L & Row 6, F-J.

Data starts in Row 7 and follows the headings. This repeats for several thousand rows. I need a way to move Row 6, F-J and put it on Row 5, M-Q

Row 6, F-J and put it on Row 5, M-Q
Row 8, F-J and put it on Row 7, M-Q
Row 10, F-J and put it on Row 9, M-Q
Row 12, F-J and put it on Row 11, M-Q
....
....
....

Then delete blank rows below Row 5

View 7 Replies View Related

Excel 2010 :: Code / Button To Automate Certain Row Heights

Dec 6, 2012

Code + Button to automate certain row heights.

1. Starting in row 5 the row height is to "30"...every 17 rows after row5 to have a height "30"...next row 22 is "30" , then row 39 is "30" and so on...
2. All rows in between row height "30" will be with a row height of "11"
3. Can this be associated with a button....
4. where would i place this code.....

Version:Excel 2010

View 9 Replies View Related

Excel 2010 :: Code For Inserting And Removing Dates

Dec 14, 2012

I need a code that when i place a date in a cell D10 (Example:25-January-2013) it will then add 40 days of dates daily to AP10.In D9 can it also add the weeknumber (every 7 days the weeknumber increases by 1) corresponding to the day date in D10 (iso).Can this be attached to a button.Enter the date in D10 then press the button and the dates auto insert across the sheet daily to AP10.

Can the button say ADD DATE or REMOVE DATES.First date in D10.When the button says REMOVE dates all dates deleted when button pressed and cell D10 then says "add date here".If no date is placed in D10 and ADD DATE button is pressed a warning messagebox appears and says NEED TO ADD DATE .Will not work until date entered.When date entered in D10 "Add Date Here" disappears until REMOVE Date button is selected and again "Add Date Here" is displayed....not sure if this is possible but would be good if achieved. Excel 2010

View 3 Replies View Related

Excel 2010 :: VBA Code To Highlight Color Through Columns

Jan 8, 2013

As seen below, I'm looking for a vba code to highlight color on every Friday and through columns 1, 4, 6,9,11,14,16,19,21 upto columns 28 i.e. AH

Excel 2010ABCDEFGHIJKLMN1DateQty1Qty2TotalDateQty1Qty2TotalDateQty1Qty2Total
21-Aug-124559289374521-Aug-122721298357041-Aug-1222792338461732-Aug-121161244636072-Aug-12347918036592-
Aug-1225723358593043-Aug-12128088221623-Aug-124369158259513-Aug-1227723299607154-Aug-124096192960254-
Aug-124679386585444-Aug-122081870295165-Aug-12333751838555-Aug-124270357278425-Aug-1231793455663476-
Aug-122061336654276-Aug-1241466142076-Aug-123761939231587-Aug-123757375975167-Aug-12212203622487-

[Code] .........

View 2 Replies View Related

Excel 2010 :: VBA - Run Code Only When Clicking In Specific Cell?

Dec 23, 2013

how to run some VBA code (written by someone else, unfortunately) only when clicking once in cell A1, and not run in any other cell. This is being run in Excel 2010. The code I would like to run in this manner is below, and currently will run when the user clicks on any cell in the worksheet it is applied.

[
Option Explicit_________________________________________
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
'If IsDate(Target.Cells(1, 1).Value) Then
Set DatePickerForm.Target = Target.Cells(1, 1)
DatePickerForm.Show vbModal
Cancel = True
'End If
End Sub
]

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved