Step Through & Debug VBA Macro Code

Jun 11, 2009

I don't understand the relationships that are happening and what the final value would be if for example the PT was Red. I'm confused and was curious how four lines could all equal different values(highlighted).

UpUserPaint = UCase(RegPaint.Value)
Dim icount As Integer
LenRegPaint = Len(RegPaint.Value)

For icount = 1 To LenRegPaint
ValPAint = ValPAint + Asc(Mid(UpUserPaint, icount, 1))
Next icount

If PTRed.Value Then
ColorCompare = Abs(Pallet * (ValPAint + PrdtSeed - LenRegPaint))
ColorCompare = Abs( Round(ColorCompare / PrdtSeed - 7227, 0))
ColorCompare = ColorCompare And 6215971
ColorCompare = ColorCompare Xor 6215971.............................

View 4 Replies


ADVERTISEMENT

OpenText Function In Macro Hangs Unless Stepping Through Code In Debug

Oct 29, 2009

We have had a macro running for a few years (Excel 2007 now, but started in 2003) that imports about 35 text files into separate sheets, creates a calculated SUM field for each sheet and copies that value to a title (or summary) sheet. We use this 2 to 4 times per year at inventory time, copying to a new file and deleting the old data before running the macro. The imported files initially create new workbooks, but the data is copied to the initial workbook into a distinct sheets for each file.

Recently (well, last August) this macro started hanging after importing (Workbooks.OpenText) a number of files, and not necessarily the same file every time (on repeated runs.) While trying to figure out the problem, I have now managed to get it to hang every time on the first file! However, if I am stepping through in the debugger it continues past the OpenText command and on F5:Run/Continue will then continue processing the rest of the files normally. If I delete the first file before running the macro, it then hangs on the second file instead.

Without debugging, the first file will import, display on-screen, and there it stops. If I put a break-point on the very next instruction after the import, that break-point is never reached. THINGS I'VE TRIED:.......

View 2 Replies View Related

Macro Executing Step By Step

Jun 5, 2008

I don't know what exactly is happening, but every step of the macro is happening every 1 second. Literally, the BPM is 60. It will execute a step in the macro every second, when in other macro's i've made, it zips right through as if it was on fast forward.

View 9 Replies View Related

How Can I Step Through Project Code

Dec 7, 2006

I am looking at the code in a MODULE, I can use "F8" to step through it.

But if I have no module just the main project code I cannot find a way to step through it.

View 9 Replies View Related

How To Step Among Entries Of Autofilter Via VBA Code

Jan 25, 2014

While I try to create a sub - autofilter A column and select the...

- first entry (but not as a unique item, as data may changes weekly) once 1st item filtered - I'd do some function: sum weekly results, and keep only one row with the filtered item (paste special/delete rows)

- than step on next entry and do the same as before

- take these steps till the end of autofilter list, than remove autofilter.

.. with this action, I'd get the sum value of my weekly forecast on each individual items.

I've started as:

ActiveSheet.Range("$A$2:$BN$400").AutoFilter Field:=1, Criteria1:= _
"17963-E050LF"

But criteria should be like .. 1st entry ... 2nd entry ... last entry .. session end .. ?!

View 14 Replies View Related

Debug Code & See Results As Stepping Through

Jun 15, 2008

When stepping through my macro it moves through each line of the code showing me the code as it steps through. Is there a way to step through and see the results of the code as it is going through. I have an "IF THEN" statement in the macro that is not giving me any results so I think I must have an incorrect reference in the code, but I can't see it. I think if I could watch what it is supposed to be doing as I step through I might be able to find the error.

View 4 Replies View Related

Code Works In Debug Mode But Will Not Run Through When Played

Mar 13, 2013

I put together about 10 separate macros that will log you into a site using the values in a given cell. I was having trouble with the last one because of AutoComplete remembering the username. So I put in an IF statement, and when I used F8 to go line for line, it works perfectly. However, when I click F5 and just let it play through, it doesn't log in. I tried adding a 5 second delay, but that didn't seem to work. I still get a run-time error when I hit play.

It get hung on this line:

Code:
If doc.getElementById("user_name").Value = cUsername Then

But the complete code is this:

Code:
Sub StreetLinks_Login()
'On Error Resume Next

Dim cURL As String
cURL = Worksheets("Sheet1").Range("B9").Value

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

View 7 Replies View Related

Disable A Step In A Macro Without Having To Delete It

May 21, 2009

How do I disable a step in a macro without having to delete it?

View 3 Replies View Related

On Error, Go Back A Step In Macro

Oct 7, 2008

I have a macro in one file which uses an input box where the user types in a subcontractor code to retrieve address and contact details from another file.

If the user inputs the incorrect subcontractor code, an error message box pops up. Currently the user then has to select a button in the original file to restart the macro at the input box stage.

What I want to happen is when ok is selected on the error message, to return to the input box so in my macro below where the error message says "An error occurred - you asked for a subcontractor that does not exist. Please try again." and the user selects OK, I would like it to return to the 'Enter the Subcontractor line and the "Please enter the Subcontractor code" input box reappears.

View 8 Replies View Related

Macro Only Runs In Step-Thru Mode

Sep 11, 2006

I have a peice of code which opens up a number of Workbooks (200+) and updates a series of control tables in each. Given our security etc environment, links and external references etc are not possible. The target files must all be standalone and self-sufficient.

The problem I have is that when I run the procedure in question in the usual way, the procedure simply terminates after the first file is opened. No error messages, no distress - it just stops. I have put debugging calls all around the "Workbook.Open" call, and it simply doesn't make it out of the call. There is no Auto_Open code in the workbooks being opened and (as I indicated above) no external links, references or function calls.

What's weird is that if I step through the procedure in the Command Debugger, everything works fine. Even weider, if I complete step-by-step processing on the first target file then I can press "Play" and the code will complete execution and process all the remaining files without error.

I have rebuilt/recreated/re-ordered the target files and even moved them to a different volume.

If anyone has seen this before, or has any idea what the cause may be, or even just a wild idea, I'd love to hear it.

Code segment attached.

*
'*** Process each file in the list provided
'*
For intCounter = 1 To intWBS_Files

Call Debug_Msg("Opening WBS File")

Application.EnableEvents = False
Set wbkThis_WkBk = Application.Workbooks.Open(strWBS_Files(intCounter), 0, False)
Application.EnableEvents = True

Call Debug_Msg(("Opened WBS File:" & Chr(13) & strWBS_Files(intCounter)))

If (wbkThis_WkBk Is Nothing) Then
Call Write_Error_Record("File Open Failed", strWBS_Files(intCounter))
Else
Code continues.....

View 6 Replies View Related

Macro Runs Fine In Debug But Not From ComboBox

Feb 24, 2009

I have a workbook that contains 9 worksheets. Four of the worksheets have the same row lables in column B and must always be the same. Three of the worksheets are fed from the 4th sheet so that the integrity of the lables is maintained.

The user can change the lable value to meet their needs and they can insert or delete rows (within limits) as they see fit.

The attached macro "Sub Delete_Row_All_Sheets()" works fine when I run it from Debug (F8).

However, when I run it from Forms.ComboBox the macro returns to the "y = Application.InputBox("Enter The Row Number You Wish To Delete", _" screen. If I select cancel, the results I anticipated occur but I don't want the user to have to assume this will happen.

Why does the macro return to this screen when executed from the ComboBox but not when executed from Debug?

View 14 Replies View Related

Macro Works In Debug Mode But Not In Runtime

Apr 7, 2008

I am trying to open a xls file and convert into csv. My macro works when I'm in debug mode. but If i run the macro (Not in debug) mode then After opening a file control is not going to next function. What is problem? Even I am not getting any error too

sub open file (FileName as string)

Dim xlx As Object, xlw As Object, xls As Object, xlc As Object
Dim RowNo As Integer
Set xlx = CreateObject("Excel.Application")
xlx.Visible = True
'Set xlw = xlx.Workbooks.Open(SourceFolder + "" + FileName)

Workbooks.Open FileName:=SourceFolder + "" + FileName
' Columns("F:G").Select
' Selection.Delete Shift:=xlToLeft
Save_in_WDrive (FileName)
Set xlx = Nothing
end sub

View 9 Replies View Related

Function Macro Debug: Continue Onto The Do Loop At The Bottom That Does All The Work

Aug 9, 2006

I am having a problem with a custom funciton I am trying to create. It will exit after it is finished with the IF Then Else statement. I need it to continue onto the Do loop at the bottom that does all the work.

Function UPCECheck( num As String) As Long
Dim CheckNum As Long
Dim TempCheck As Long
Dim X As Long
Dim Holdtxt As Variant
UPCECheck = 0
CheckNum = 0
Debug.Print Len(num)
If Len(num) = 12 Then
Holdtxt = num
ElseIf Len(num) < 12 Then
Holdtxt = "000000000000" & num
Holdtxt = Val(Mid(Holdtxt, Len(holdtext) - 12, 12))
End If...................

View 6 Replies View Related

Code "debug" Error 13

May 29, 2009

The two code extracts below are associated with two separate worksheets in the same workbook. They work fine. They simply are used to assign either a PO# or a Temp Unit #, located in a third sheet, in their respective sheets.

The problem is that when I'm in either the Master or the Work Orders sheets where these two codes are used, and I do something simple like drag down some values or paste something in a cell, I get the "Run time error "13" type mismatch error" in the popup debug window for my VBA code. And in each case, it highlights the codeline I've color coded below:

View 2 Replies View Related

If Then = Debug

Sep 23, 2009

Why does this give me a debug error?

View 4 Replies View Related

Two Different Passwords Without Debug

May 9, 2008

I have a problem with a HUGE macro project I'm working on. The macro itself isn't huge, but it's being applied to about 10,000 files. The macro is updating information on three spreadsheets in each workbook, but the problem is that the password protection (and Macro in general) fails to unlock when the password was entered in UPPERCASE. So the password is "king" and/or "KING" depending on the sheet. There is no way of predicting which sheets will be caps and which will not, but it's frustrating when my macro stops every 5 files with an error because of a wrong password (even though it's always one of those two).

Is there an IF THEN statement or something that I can do so that the macro doesn't stall every 30 seconds to 2 minutes... I have 10,000 files to crawl through.

View 10 Replies View Related

Debug Error 13

Jun 22, 2009

I have a working Excel 2007 macro that accesses two worksheets. I then added a third worksheet and want to access it from the macro. I get a debug error 13 Type Mismatch when the macro tries to access the third worksheet. I know I need to add the third worksheet on a pop-up but I don't remember how to open it.

View 14 Replies View Related

Debug Statement

Dec 5, 2008

I am trying to put together an automation. I am having problem debuging the code. I am trying to have the automation autofilter with "Interior" and "Exterior" at column P. I am using a statement as follow to pick the cell that is showing at at second row each time after the autofilter ran. (the first row of Exterior and Interior are different) However, when i pick Exterior, the automation was able to locate the second cell after picking Exterior, but when I try Interior, then i will have a debug meesage.

Range("Q2:Q" & Cells(Rows.Count, 1).End(xlUp).Row).SpecialCells(12)(1).Select

The code that I used is as follow:

Sub Macro4()

Range("L1").Activate
Selection.AutoFilter
' Selection.AutoFilter
Selection.AutoFilter Field:=15, Criteria1:="=*Fixture*", Operator:=xlAnd
Selection.AutoFilter Field:=16, Criteria1:="="
Range("P2:P" & Cells(Rows.Count, 1).End(xlUp).Row).SpecialCells(12)(1).Select
ActiveCell.FormulaR1C1 = _

View 9 Replies View Related

Debug :: I Get: Division By Zero

Dec 15, 2009

When I debug this script I get: division by zero!

In 3 lines over the debugging line, the script are writing out the variable "prosentref" as 1. Whatt can be wrong?

(the value in cell T8769 is 1)

Option Explicit
Sub optimaliseringDrift()
Dim Pgm1 As Integer
Dim Pgm2 As Integer
Dim PL As Integer
Dim lamda_gm1 As Double
Dim lamda_gm2 As Double
Dim deriv1 As Double
Dim deriv2 As Double
Const Pgm1_max As Integer = 200
Const Pgm2_max As Integer = 300
Const Pgm1_min As Integer = 45
Const Pgm2_min As Integer = 40
Const deltaP As Integer = 5

View 9 Replies View Related

Using Step In A For Loop

May 7, 2006

I'm trying to run a loop that doesn't go through every value between the lower and upper bounds so am using Step at the end of the For line:

For j = 0 To s Step loop_step
'Does stuff in here - not relevant
Next j

The amount that is being stepped through is set as a variable previously - called loop_step, and works fine for small values (e.g. stepping through 10 at a time) but comes up with an error for 1000. I haven't checked how large the value needs to be before it creates an error, but I was wondering if anyone knew if there's a limit on the number you can step through? Otherwise I have no idea what's causing this problem!

View 6 Replies View Related

Vba To Step Thru And Edit Data

May 26, 2008

I get a report that I have to manually edit everyday. I've done some VBA, but not sure where to start with this one.

The attachment has two sheets, first is what I get and the second is what I want. I'll explain the process i have to go thru now and maybe I can get some help to automate it.

First
-Add the tech number to the first column for each job for each tech.
7988 us the first tech number.

-Then delete every row that isn't a job.
-Add a column with the install date.(report data near the top.)
-Add a column and populate it with the system, which is the sheet name.
Thats why its example.

View 14 Replies View Related

Debug: Subscript Out Of Range?

May 29, 2009

trying to copy some records across from once sheet to another?

butt it keeps debugging?

any idea why.

i'd like to keep the user defined type because it's neat and is good practice for myself?

View 9 Replies View Related

Getting Range To Step Through In A Loop

Apr 6, 2012

This little piece of code is where I'm having problems.

A36:A45 will always be the same.

The problem is in getting ("R2:AA2") to move to ("R3:AA3") ...

What needs to happen for the loop to work?

Code:
Worksheets("List").Select
Range("A36:A45").Select
Selection.Copy
Worksheets("Month").Select
Range("R2:AA2").Select

I've tried:

Dim rngDC as Range

then Set rngDC = Worksheets("Month").Range("R2:AA2")

So that I can later use rngDC = RngDC.Offset(1,0)

However, when I try rngDC.Select I get an error saying I can't select the variable that way.

Here's the complete code:

Sub Import()

Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True

With Sheets("Month")

[Code] ....

View 2 Replies View Related

Step Through Works But Not When Activated

Sep 24, 2007

I have written this code to change the colour of a row of cells to bright green and to change the cell contents of cell(Row, 15) from “L” to “F”: This is the main workbook into which are pulled values from three others. I then want it to open one of the subsidiary workbooks, that feeds the information, to change the same job row to bright green and to change the cell contents of cell(Row, 15) from “L” to “F”. Then I want to save the changes and return to the main sheet: - The ActiveCell contains the Job Number.

Option Explicit
Public rw As Integer
Public Col As Integer
Public Job As String
Public JobNo As String
Public RowNo As Integer
Public wName As String
Public times As Integer
Public Pips As String
Public Nicolas As String
Public Cindys As String
Public wb

Sub FinishedinOfficeCindy()
.
rw = ActiveCell.Row
JobNo = ActiveCell
Col = ActiveCell.Column
If Col 1 Then
Check that the correct
MsgBox "Please choose the Job Number first"column is selected and
Exit SubThat the workbook is
End Ifthe correct one
If Cells(rw, 14) "Cindy" Then
MsgBox "Wrong Secretary Chosen - whoops!"
Exit Sub
End If

All works perfectly when I step through it but, when it is activated (Ctrl+Shift+C) it opens the other workbook and then seems to end? I even tried putting in delays to see if they would help but they didn’t.

View 9 Replies View Related

Single Step Window

Oct 31, 2007

I do have code, but this thing (which appears on the Excel window, not the VBE window) doesn't seem to be connected to any of my code.

What is this, and what caused it to suddenly pop up on me in Excel?

View 9 Replies View Related

Different Results When Running Vs Step Through

Jan 12, 2010

My workbook contains several worksheets with queries to external SQL Server database. All queries use background updates. Each query uses a parameter for the SQL query string. The parameter value is obtained from E2 Reports!B4. Manually changing this cell returns results on worksheet Job Summary in range("A6:K6"). This works great!Worksheet Order Details contains a list of job numbers in column B.

I wrote a VBA sub that loops through these jobs, changing E2 Reports!B4 for each job. I then call the Application.RefreshAll function. Finally, I copy "Job Summary!A6:K6" to a row on worksheet Order Summary. If the next job is the same order, I copy with a paste special to add the results.The problem occurs when running the VBA sub. If I step through the code, waiting for the RefreshAll function to finish, the correct values are returned. If I step through fast, without waiting for the RefreshAll, the values for some jobs are copies of the previous job, but other jobs are correct. If I hold the F8 key down or hit the F5 key, all values are the same as the first job.I've tried DoEvents, turning off screen updates, and turning off background updates.

Private Sub
Worksheet_FollowHyperlink(ByVal Target As Hyperlink) If Target.Name = "Order Summary" Then ' rj references position on Job Summary sheet Dim rj As Integer ' ro references position on Order Summary sheet Dim ro As Integer rj = 6 ro = 6 ' clear all rows Sheets("Order Summary").Range("a6:a65536").EntireRow.Clear Application.CutCopyMode = False ' turn off screen updating to avoid flicker..........................................

View 10 Replies View Related

Customizing Debug Pop Up Window

Aug 23, 2006

If a user decides to hit the esc key right in the middle of one of my procedures (bug free, etc), this will leave the file in an odd state. The file is set up so if the routine is re-run it cleans the file up and restores it to proper form.

But hitting esc exposes my code which is password protected when the file is idle. I employ a little trick that makes it hard to hack into my worksheet code, but one achilles heel is the esc button.

What I want is to have the file close if the routine is stopped in mid stream. This way the code is not exposed, and the user cannot monkey with the file.

I wanted to set the file up where i have a custom debug window that when a button is pressd the file closes OR when the user escapes out of the debug window the file closes as well.

View 9 Replies View Related

Find Function Debug

Feb 15, 2007

What I'm doing in this script is taking a whole bunch of variables and pasting them into a seperate sheet "Checks" which will construct a cashiers check. The problem is where I've highlighted the code in red. At that point I have copied the Vendor name to the clipboard - I then go to the "Vendor Info" page and search for that Vendor name. If that name exists on the page it works perfectly...moving one column to the right, grabbing the Address Line 1 and dropping it into the check, then going back and grabbing the Address Line 2 and dropping it into the check. The problem is when that Vendor name doesn't exist in the "Vendor Info" page...I want it to just paste two blank cells into the check (because I obviously don't have the address info for that Vendor)...but instead it gives me an error:

Run-Time error '91':

Object variable or With block variable not set

Sub Checks()
'
' Checks Macro
' Macro recorded 2/14/2007 by Derek Minner
'
' Keyboard Shortcut: Ctrl+Shift+P
'
Selection.Copy
Sheets("Checks").Select
Range("I4").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

View 3 Replies View Related

Step Calculation Formula

Apr 14, 2007

I have a simple calculation - Say 0-6. What i need to do is, if the value is <7 place a 10 in the cell, or if the the value is <12 place a 5 in the cell, or,
lastly if the value is <21.5 place a 0 in the cell. Is this at all possible - as i can only do it with conditional formatting using colours at present

View 7 Replies View Related

Debug.Print Cause Crashes

May 18, 2007

Continuing with my goal to learn VBA and while playing with the following code, I encountered strange behavior of debug statements. In the code below I have put my comments to identify where the "funny behavior" is encountered.

Will appreciate if you can help me understand. I also have a simple request/question at the end of the code below: ....

View 7 Replies View Related







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