VBA Code Quicker Than Just Writing Out The Calculation In VBA

Oct 9, 2006

Does Excel handle formulas written into the VBA code quicker than just writing out the calculation in VBA?

I have a section where I use the following formulas, sumif, countif and a combo if iserror sumproduct in the VBA code...runs rather slow at this point and was looking at a way to speed things up.

View 9 Replies


ADVERTISEMENT

Quicker Copy/Paste Range

Dec 16, 2009

I have the following code which copies and pastes a range of cells in a row from one sheet to another if a condition is met:

View 9 Replies View Related

Writing Vlookup Into VBA Code

Aug 15, 2007

I need help writing the VLookup function into a VBA macro.

I currnetly have a macro that generates a list of companies in column D on Sheet1. There could be a different number of rows populated every time the macro runs.

I also have a list of all the possible companies next to their e-mail address on Sheet2 (company in column A, corresponding e-mail in column B).

I know Vlookup can search sheet2 and populate the correct e-mail address on sheet1, but I want a VBA solution in which it will automatically see how many rows of companites I have, perform Vlookup for each company, and place the corresponding emails in sheet1, column E.

View 9 Replies View Related

Writing Long Lines Of Code

Aug 29, 2007

I've written a piece of code that is so long, I have to use the scroll bar to see the whole of it, which isn't very user friendly

if there's a way of splitting long lines of code over say 2 or 3 lines, so I can read the whole thing without having to use the scroll bar? I've noticed some people use _ at the end of the code and then continue writing on the next line, but when I do this, I get an error message saying

"Compile Error : Expected : line number or label or statement or end of statement"

View 9 Replies View Related

Writing VBA Code To Add Borders To Selection

Mar 4, 2008

I got some code from an old discussion thread


Sheets("Reference").Select
Range("d9").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select

Dim myBorders() As Variant, item As Variant
myBorders = Array(xlEdgeLeft, _
xlEdgeTop, _
xlEdgeBottom, _
xlEdgeRight, _
xlInsideVertical)

View 9 Replies View Related

Writing The VBA Code For The Objects Created During Execution.

Apr 27, 2006

See the attached Workbook, which explains the problem easier.

View 9 Replies View Related

Writing Code To Copy / Insert And Paste To Worksheet

Oct 11, 2013

writing a code where i can copy a worksheet (Sheet1), insert a new worksheet at the END (as the last worksheet), and paste to that new worksheet (which will have a different name each time a new one is added). I am using the code below, but it adds a worksheet after Sheet1 instead of at the end, and it also adds another weird worksheet that says "Dim Worksheet" in one cell, and "Set newsheet = Sheets.Add(After:=Sheets(Worksheets.Count), Count:=1, Type:=xlWorksheet)" in another. This is not in the VBA window, it is just text in a cell in another inserted worksheet. I only want one worksheet added at the end that I can paste too (knowing that the inserted sheets will always have new names).

Code:
Sub CreatePercentageSheet()
ActiveWorkbook.Sheets("Sheet1").Copy _
After:=ActiveWorkbook.Sheets("Sheet1")
ActiveWorkbook.Sheets.Add After:=Worksheets(Worksheets.Count)
ActiveSheet.Paste
End Sub

View 2 Replies View Related

Difficulty Writing Code For Changing Font Color If Cell Contains Specific Text

Aug 11, 2009

I have a spreadsheet that will contain about 5-15 rows with a letter "S" in the column. If this letter S appears in the column, I need its entire row to change font color to RED and then change that row's value in column L to a negative number. is there any easy way to do this?

View 14 Replies View Related

Faster Calculation Than SumIf Code

Nov 21, 2006

I have the following code performing SumIf and searching roughly 9,000 rows of data. Calculation takes roughly 15 seconds on the high side.

Bonus question from a rookie - This code runs well in Sheet2, but errors out on the SumIf's when placed in a module or userform. What needs to be changed for it to work outside of Sheet2?

Private Sub DistNeg_Click()

Dim BotRow As Long

Application.ScreenUpdating = False
Worksheets("Sheet2").Range("A4:E65536").ClearContents
'Copy current selected Distributor names to sheet2
Worksheets(1).Range("DIST1").Copy Destination:=Worksheets(2).Range("A4")
'Define the bottom row of distributors in this list.
BotRow = Worksheets(1).Range("DIST1").Rows.Count + 3
'Sum for PY, CY and $CHG sales. Create percentage Chg column.
Worksheets(2).Range(Cells(4, 2), Cells(BotRow, 2)).FormulaR1C1 = "=SUMIF(Sheet1!

View 9 Replies View Related

Excel Formula / VBA Code For Time Calculation

Aug 14, 2012

I am calculating the employees time and need the time spent to be categorized as follows

Monday to Friday
06:00 to 09:00 is OT
09:00 to 17:00 is BASIC
17:00 to 00:00 is OT
00:00 to 06:00 is PREMIUM

A2 =Date= 31-07-12
B2 =Start Time = 03:00
C2 = End Time = 23:00
D2 = c2-b2 = 20 hours formatted as [h]

there are situations when end date and time is the next day

E2 = 8 hours
F2 = 10 hours
G2 = 3 hours

Saturday
07:00 to midnight is OT
Midnight to 07:00 is premium

Sunday
all the time is premium

View 1 Replies View Related

Code To Apply Calculation To Different Sets Of Data

Mar 5, 2013

I have an excel spreadsheet that performs a particular calculations using a large set of data. However, I have over 1000 sets of data that need to be feed into this sheet and obtain the output calculation. Obviously I don't want to have to copy and paste in each new set of data to obtain my result as this would take a very long time. I am brand new to VBA, so was wondering if there is a way to write code in VBA that will automatically perform these calculations for one data set, save the output into a cell, and then move to the next data set and so on?

View 4 Replies View Related

Calculation Code For Calculator Runs Slow

Oct 1, 2006

I am making a small push button calculator to enter data into a textbox on a userform in an add-in file and this works fairly slowly. I am trying to concatenate a list of numbers in a textbox that simulates a calculator screen when entering numbers.

Private Sub CommandButton6_Click()
Dim Val
Val = "6"
Dim valand As Range
Set valand = ThisWorkbook.Worksheets("Stageing").Range("K65536").End(xlUp).Offset(1, 0)
valand = Val
Dim A As Range, B, C, d, E, F, G, H, I, J
Set A = ThisWorkbook.Worksheets("Stageing").Range("K2")
Set B = A.Offset(1, 0)
Set C = B.Offset(1, 0)
Set d = C.Offset(1, 0)
Set E = d.Offset(1, 0)
Set F = E.Offset(1, 0)
Set G = F.Offset(1, 0)
Set H = G.Offset(1, 0)
Set I = H.Offset(1, 0)
Set J = I.Offset(1, 0)
TextBox1.Value = A & B & C & d & E & F & G & H & I
End Sub

View 4 Replies View Related

Option Button (active Control) Code To Perform A Calculation

Nov 18, 2008

is it possible to choose an option button which will then perform a calculation on a cell reference? I’m trying to deduct a percentage from a total when an option button is highlighted.

View 5 Replies View Related

Writing Value 0 In Different Ranges?

Nov 13, 2012

I have a table in which some of the ranges have to be set to "0" (write "0" inside, not delete) when I click on a button. All the other cells expect these ranges are locked. For now I use the very long way, with the following VBA Code:

Range("E7").Select
ActiveCell.FormulaR1C1 = "0"
Selection.AutoFill Destination:=Range("E7:E21"), Type:=xlFillValues

[Code]....

There are more columns for which I have to do that, and it goes until row 500+ .. I used "Register Macro" to find out this code, that's why I guess it's obselete.

Is there any way I can do it, at least write all the ranges I have to fill with "0" next to each other instead of every time selecting, then inserting 0, then autofill the rang with...?

View 9 Replies View Related

Writing A Between Statement

Dec 15, 2006

I have a list of items in a pivot table where each item has a date. I want to see how many items occur for each month. I am trying to use the COUNTIF formula, but I'm having trouble figuring out how to write the criteria for the dates.

How do I write the criteria part to include the entire month?

View 9 Replies View Related

Writing Macro

Jul 3, 2007

i have an report in which i need to delete the entire row if the column contains values more than 250K, but the chanllenge here is; if any of the cells in the column contains a formula then the macro should not delete the row.....

View 9 Replies View Related

Writing To Word

Sep 25, 2008

if I have another instance of word open my macro will not work correctly. I am at a loss on how to figure this out. Also some times I get the error of virtual machine is not available when getting activedocument.name.

Sub TestTemp()
Application.ScreenUpdating = False

Dim bname as string

bname = Range("B6").Value

Dim WdApp As Object, WdDoc As Object
Set WdApp = CreateObject("Word.Application")
WdApp.Documents.Add "C:TemplatesTest Letter1.dot"
Application.Visible = True
WdApp.Visible = True

AModDoc = ActiveDocument.Name

Documents(AModDoc).Bookmarks("Line1").Range.InsertBefore bname

Application.ScreenUpdating = True
End Sub

View 9 Replies View Related

Writing Subroutine

Oct 27, 2008

in writing a subroutine that needs to ask the user

1) tax file number
2) Income
3) tax withheld

It then needs to use a function that i already made called 'incometax' that calculates 'taxpayable' and use that to calculate taxreturn (difference between 'taxpayable' and 'taxwithheld').

I then need it to output like this in a message box

Estimate for tax file number: .....
Created on ......
Total income: ......
Tax witheld: .......
Tax payable: ......Tax return: .......

View 9 Replies View Related

SelectCase Not Writing Value

Nov 15, 2008

The following code is supposed to write values from one file into another file - depending on the value of Current_Rider_Name. However, although the code runs and values are being picked up (this is checked through the line that is being commented out).

However nothing is being written to the file. Can anybody point me in the right direction? ...

View 9 Replies View Related

Writing An IRR Function In VBA

Aug 16, 2009

way to write your own IRR function using VBA.

Say if I call it Function MYIRR(cfs,per). Where cashflows occur in the periods specified..
i.e
Periods: 0 1 3 4 6
Cashflows: -1000 300 500 100 200

I'm having trouble making sure the initial cash outlay and then cash inflows assumptions hold (problem with the -/+ sign).

I've been told by a friend to try and use abs() function, 'For..Next' loop construct inside a 'Do...While' loop.

View 9 Replies View Related

Writing Udf For If Color Then Else

May 2, 2007

I am trying to write a UDF that will go like this:

IF A1 is Purple then B1=A1 Else B1=A2.

This is what I have written so far and I cannot figure out how to get it to work:

Function SumIfPurple( Range As Variant, Range1, Range2)
Dim SumAnswer
If Range.Interior.ColorIndex = 39 Then
Range1 = SumAnswer
Else: Range2 = SumAnswer
End If
SumIfPurple = SumAnswer

End Function

View 7 Replies View Related

Writing Text In A Cell

Jan 21, 2010

I have a problem, basically im writing in the cell but it keep going along, i want it so when i press enter it creates a new line in the cell, so i can have two lines of text in one cell. do i have to do something in the text settings?

View 2 Replies View Related

Writing In Two Cells One Word?

Apr 22, 2013

I'm trying to write a word or more but i want it to be in different cell.

Like: this sentence "Excel Program" write it in cell a1 but it slip to the cell a2. (so in cell a1 adn a2 this sentence).

View 4 Replies View Related

Writing Formula In Cell Using Vba?

Apr 8, 2014

I have a reference written as a string in cell "AS4", the string is results!A4

I want to write that same reference in cell "as5". I have written the following

[Code] .....

However, cell "as5" returns the string as =results!'A4', with single quotes around A4

Therefore the reference isn't working.

View 2 Replies View Related

Writing VBA Macro Or Function

Nov 5, 2007

I have Asset Class in Column I and if it is 364A-EL or 365A-EL or 368A-EL or 368B-EL or 369A-EL or 371A-EL or 371B-EL or 373A-EL or 397C-EL then 'POLES' assigned in to Owner Class (Column J).

If Asset Class is 366A-EL or 367A-EL or 367B-EL or 368C-EL or 369B-EL or 371C-EL or 373B-EL then assign UGCBL to Owner Class.

Should we write the macro or can it be accomplished by any Excel Function?

View 11 Replies View Related

Writing Array To Cell

Apr 15, 2009

I'm working on creating an array of letters. I'm then writing that array into a cell. The following code is for writing the letters "ABC" into a cell with an array.

View 4 Replies View Related

Writing Numbers Using Macro

Oct 16, 2009

I'm trying to use code to write the numbers 1 to 100 in 10 rows of 10

1 2 3 4 5 6 7 8 9 10
11 12 13 14 15 16......................

So far i have the following which works:

View 4 Replies View Related

Writing ActiveWorkbook Name To A Variable

Nov 17, 2009

I run the macro on a currently open workbook (name could be anything) and open another workbook (name known) and step through the sheets copying various blocks of data across to the first workbook. I need to Activate the 2 workbooks alternatively as I move data back and forth and move from sheet to sheet. What I can't work out is how to determine in code what the "unknown" workbook name is so that I can make sure I activate the right workbook in the code.

I tried Activating the workbook with the "unknown" name and setting a variable = ActiveWorkbook.Name. However the value of this variable changes during the code run when you activate the other book. Is there any way to collect this value and "freeze" it so it won't change as the code runs? At the moment I have got round it by ensuring the "unknown" book is the only one open before I start and refer to it as Workbooks(1) in the code.

View 2 Replies View Related

Writing Macros Sheet

May 6, 2006

i've a macro which will read the data from worksheets and copies that data
and paste the copied data into new workbook sheets.

it is copying the data into new work sheet. whats my problem is my original
application contains formatted data like having cloros and some of the
columns having big font size etc and some of sheets contains merged cells.

i'm totally having 8 worksheets with different layouts and the macro copying
the data into 8 new worksheets but the look and feel is not similar to the
original application. But i want as it is.

View 13 Replies View Related

Writing Data From Excel To PDF

Mar 9, 2012

I have been working with Excel, access and vba from 4 years. But never worked with PDF files along with vba.

Now I have a requirement to write data from excel to pdf. I know about using Acrobat distiller to create Post Script file and then converting into pdf files.

But I wanted to know if there is any way to write data directly into PDF from excel using VBA.

View 6 Replies View Related







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