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


ADVERTISEMENT

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

Allow User To Enter Break Mode (Debug)

Jan 4, 2008

i want to do is throw a break in my vba code if the user selects yes through a msgbox vbYesNo prompt and proceed in debug mode. is it possible to code in a break point in this fashion? my desired pseudo

if user selects yes:
set break point (to send to debug mode at that point... i dont mean to end the code with a END statement.)
if user selects no:
proceed program normally

View 6 Replies View Related

Function Works But Get Runtime Error 13?

May 20, 2014

This is a function to add the ascii values of a string to give a single value. Initially I wrote this as a Sub routine and it worked fine, but when making it into a function, I get this error. From a little research it appears that you can not use a string as an argument for a function call, yet that defeats the object of this particular function.

The intention of this function is that it works on a name in a given cell and the value (an integer) that is produced is then displayed in another cell, or if using it as a formula, the cell the formula is in.

I simple wrote the work "Hello" in cell A1 the ascii values of these added ignoring any spaces give 500 which is correct.

View 3 Replies View Related

Error In Runtime First Go, No Error In Debug Or Second Go

Jul 6, 2006

The code thats generating the error is the following:

For Y = 8 To 131
TmpDate = Empty
Range("A1").Value = "=" + Path + Sheet + "B" + CStr(Y)
TmpDate = Range("A1").Value

For Langd = 1 To Len(TmpDate)
TmpChar = Mid(TmpDate, Langd, 1)
If Not TmpChar = " " Then
TmpComp = TmpComp + TmpChar
End If
Next Langd

TmpDate = TmpComp
TmpComp = Empty

If Len(Dag) = 1 Then
Dag = "0" + CStr(Dag)
End If

Macro continues before the Next-statement...

(it might not be good programming, but I think it should work).
A little explanation to the code.
I have a spreadsheet located on the intranet that has values I need in my spreadsheet. These figures are sorted by date, so I search for the date to find the right figures.
The line Range("A1").Value = "=" + Path + Sheet + "B" + CStr(Y)
works prefectly. I can see the value in my spreadsheet in the cell A1. its the next line that causes the error "Type mismatch".
The value I get from the intranet spreadsheet looks similar to this:
"1 Jul 2006 " (note all the spaces).
What I do is just run it through a loop and cut of all spaces so it will look like this: "1Jul2006" to be sure I dont miss a space or anything.

Now to the funny part.
The error only happens at runtime on the first go.
If I chose to END the macro then and there, and then run it again from the top it works perfectly.
If I set a stopsign to debug the code, it works perfectly on the first go too.
Can anyone explain to me why that happens??

I know enough about programming to handle my syntax errors and so on, but I cant see anything wrong in this one...

Please note that this isnt the the entire code.
I'm building a report on 12 diffrent spreadsheet. The main macro is almost 2000 rows of code, and it call other Subs too (because of limitations in the VBA-editor. A macro cant to be too big), so its impossible for me to post the entire macro...

View 9 Replies View Related

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 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

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

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

Run Macro While In Edit Mode

Jul 24, 2007

I cannot run code from the formula bar.

I have a context sensitive menu

Sub AddContextMenu()
On Error Resume Next
Application. CommandBars("formula bar").FindControl(msoControlButton, 0, "MYMENU").Delete
On Error Goto 0
Dim objTemp As CommandBarButton
With Application.CommandBars("formula bar")
Set objTemp = .Controls.Add(msoControlButton, , , .Controls.Count + 1, True)
With objTemp
.Caption = "Formula Menu"
.BeginGroup = True
.OnAction = "TestMe"
.Tag = "MYMENU"
End With............

View 9 Replies View Related

Macro To Paste While In Edit Mode

Aug 18, 2008

Is it possible to write code to paste a string in text select (double click in a cell) mode rather than cell select (single click a cell) mode? I need a string to paste in as if someone had double clicked then hit paste (so as to utilize special delimiters.) Here is the code that reads the workbook, finds the next available row, then pastes:

Dim strCopyToLog As String
strCopyToLog = Range("Q2")
Range("Q2").Select
Selection.Copy
Range("b1.b5000").Find("").Select
ActiveCell.Value = strCopyToLog

View 2 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

Run Macro While In Cell Edit Mode

Dec 1, 2006

I have Form Button in Excel Sheet which Calculates by reading other excel sheet. Now the problem is when user enters data in a Cell by double Clicking on it and after entering data if he directly clicks on a button then Macro that needs to be invoked is NOT executed. The only way is that he needs to press EnterKey OR Click on any other Cell and then click on the button.

View 4 Replies View Related

Rum Macro While Cell In Edit Mode

Oct 19, 2007

I have users who don't press Enter (or move to a new cell) after entering text. They then try to click a form button - and of course - the macro does not run.

Is there an xl/vba solution to force them out of edit mode before clicking the button?

View 6 Replies View Related

Run Macro While In Cell Edit Mode ..

Apr 3, 2008

In an Excel worksheet all command buttons are disabled while a cell is in edit mode or while the cursor is active in the formula bar. Is there a way in VBA to save the cell's contents and execute a command button if clicked while a cell is in edit mode?

View 2 Replies View Related

Run Macro After Leaving Shape Editing Mode?

May 14, 2014

I've got a macro function which calculates the area of a polygon freeform using the 'shoelace'-methode. I would like to excute this function after i leave the shape editing mode.

For example: I have a square, freeform shape. By right-mouseclick I can edit the shape nodes. If i drag one of the nodes of the square to another position and click outside of the shape, the new shape is updated. Right, on that moment i would like to trigger my macro to recalculate the area.

Is there an event in excel to aim for, like the Worksheet.change-event or something similar?

View 2 Replies View Related

How Do I Create A Macro To Work In Shared Mode

Nov 11, 2009

Ive got a problem with a work book im working on at the moment, my company has various different documents created in excel, like a price list, cost price list & stock levels (all Independant) I have had the idea to join them all into a single shared workbook using an idea I found and modified over a year ago on this site, that had the promise of allowing multiple users to see the nessesary parts of the same document. the advantage of this being any new parts or prices or suppliers added would update all users at once. So ive got this workbook that when you open you get asked for a username & password this then hides/unhides, protects or unprotects to suit the users needs. This works great when unshared but when I share it the login box wont display

The Administrator username is jamie and the password is joshua

View 10 Replies View Related

Macro Works Stepping Through But Not When Run On Its Own?

Jul 21, 2014

I have a very simple macro that copies data from one worksheet to the other. This macro worked fine in Excel 2007. I have since migrated to to 2013. The newly arisen problem is that when I run the macro, the data is not copied to the 'Previous Part Data' worksheet. However, if I step through the code line by line, it works fine.

Here is the code:

VB:
Sheets("Current Part Data").Select 'Select the 'Current Part Data' worksheet
'Copy the data to the 'Previous Part Data' worksheet then clear the data
Range("A4:V" & CurrentPartDataFinalRow).Copy

[Code]....

I have two questions:
1. Why did this work in 2007 and not in 2013?

2. Is there something I can do to get rid of the sheet selection statements to avoid cluttering my code?

View 3 Replies View Related

PDF Macro Works With Windows But Not On Mac

May 18, 2014

I've sent the file to 2 different windows computers and it works fine, but doesn't work with the two macs that I've sent it to.

This is the code:

[Code] .....

View 2 Replies View Related

Macro Works On One Sheet But Not The Other

Mar 31, 2014

In the following user defined function

Code:
Function CA2GT(ByVal S As String) As String
Dim x As Long, CA As Long, Total As Long
CA = InStr(1, S, "CA", vbTextCompare)
For x = CA To Len(S)
If Mid(S, x, 1) = "(" Then

'replace arguments: oldtext, start at number, number of characters, new text

[Code] .......

It works on one workbook but not another workbook. Why?

View 5 Replies View Related

Macro Works In 97 & 2000 But Not 2003

Mar 15, 2007

I convert text file into Excel. Then what I want is to look in column C for cell value “UNT:” (it is chopped word account: ) and copy value what is in the same row next column D into column K.

Then in column K copy down the value until next not empty cell.

My problem is that it works on Excel 97 and 200 but 2003 doesn’t work.

View 9 Replies View Related

Macro That Doesnt Work In 07 But Works In 03

Oct 28, 2008

I've been searching around here to see if anyone had an answer about codes and macro changes from 03 to 07. The closest thing I found was something about lists being tables and such. However, I am still unsure of what the issue might be in my case.

Sub ArrangeColumns()
'
' ArrangeColumns Macro
' Macro recorded 3/7/2008 by ****
'

'
endRow1 = ActiveSheet.UsedRange.Rows.count + 1
Range1 = "A1:O" & endRow1

Range(Range1).Select
Range("A3:O39").Select
Application.CutCopyMode = False
ActiveSheet.ListObjects("List1").Unlink
ActiveSheet.ListObjects("List1").Unlist
Columns("A:B").Select
Selection.Delete shift:=xlToLeft
Columns("I:I").Select
Selection.Cut
Columns("B:B").Select
Selection.Insert shift:=xlToRight
Columns("L:L").Select
Selection.Cut
Columns("C:C").Select
Selection.Insert shift:=xlToRight
Columns("M:M").Select
Selection.Cut
Columns("E:E").Select
Selection.Insert shift:=xlToRight
Columns("L:L").Select
Selection.Cut
Columns("G:G").Select
Selection.Insert shift:=xlToRight
Columns("B:B").ColumnWidth = 11.29
End Sub

So here, the red text is what gets flagged when you run the macro. I seem to be getting a Run-time error '9': Subscript out of range error.

I am not exactly sure what the macro does besides clean up and sort a portion of a worksheet. Also, there is not worksheet called "List1," but changing that value does nothing. Is there an equivalent command to those highlighted in red? Or, perhaps if anyone knows of a place where I may reference these commands myself, that would be great as well.

View 9 Replies View Related

Autofilter Macro Works On One Column, But Not The Other

Jul 7, 2006

I'm using Excel to map automotive parts to vehicle applications (two different spreadsheets) for importation into a relational Access database. Production dates for parts rarely match the on-sale dates of the cars, so I've set up a macro that:

1. copies the start production date for a part record into the vehicle workbook at the top of the 'discontinued' column,
2. copies the end production date for the part into the vehicle workbook at the top of the 'release' column,
3. uses these pasted data points as criteria for the autofilter in the vehicle workbook as 'vehicle release date' < 'part end production date' and 'vehicle discontinued date' > 'part start production date'.

I find that the macro works perfectly in the autofilter for the vehicle discontinued date, but not for filtering the vehicle release date. The date is copied and pasted OK. When I check the custom filter dialogue box, the date has been entered in with the 'is less than' menu item selected, but it doesn't bring up any records unless you click on the 'OK' button once the dialogue box is open. I want to run the macro without having to run the autofilter manually at all. To troubleshoot the issue, I broke up the macro into two separate macros, one for release and the other for discontinued. Problem remains, even though the only difference between the two macros is the relative cell addresses. I've checked formatting of the cells for text vs. numeric and that doesn't appear to be a problem.

View 4 Replies View Related

After Printing, The Macro Works Very Slow

Apr 5, 2007

I programmed a simple macro (attached to a button) that scan the lines in the sheet and uses the function: Cells(y,2).EntireRow.Hide=TRUE (in order to hide certain lines). Usually, It runs fast without problem. But when I print out an area of the sheet, it cause the macro to slow down substantially. (when it runs again). In order to fix that , I had to close the file and reopen it again ( and not print out)

View 7 Replies View Related

Macro No Longer Works - Getting Compile Error?

Jul 30, 2014

I created three macros to work with reporting for my company.

One sorts a field, another deletes unwanted columns, and the third double checks columns for answers--I work for a telecom polling firm.

It was working last week on my computer, and it still works on another computer at the office. However, I keep getting an error message when I try to run it.

The message is "Compile Error: Expected Function or Variable". The code is below, and bolded where it breaks down.

--selection.Autofilter

[Code] .......

What could be the rationale for the sudden breakdown? I was testing it on a file that I have tested with before without issue. I also tried a second file, and even restarted my computer. I am currently trying to write a fourth macro for counting responses and giving percentages, so while I don't need to have the perfectly cleaned data to do so it would be nice to have.

View 4 Replies View Related

Countif Function In A Macro: SUM And COUNTA Works

Jan 27, 2009

I'm using the SUM, COUNTA and COUNTIF functions in a macro. The SUM and COUNTA works but the COUNTIF function does not return results.

Sub B_Test()
Dim myRange
Dim Results
Dim Run As Long
myRange = Workbooks(1).Worksheets("Master").Range("S6", Range("S6").End(xlDown))
Range("M3") = Application.WorksheetFunction.Sum(myRange)
myRange = Workbooks(1).Worksheets("Master").Range("D6", Range("D6").End(xlDown))
Range("D3") = Application.WorksheetFunction.CountA(myRange)
End Sub

I have tried countless ways to rewrite the COUNTIF line with no results or compiler errors returned. Originally had problems with the SUM and COUNTIF function and found that column formating was the problem. After clearing all column formats, the SUM function promptly began working but the COUNTIF keeps eluding all my efforts. The column which the COUNTIF is pointed to contains values of 0 to 500. Only values greater than 0 are to be counted.

View 2 Replies View Related

Save As Date Macro Works But Not On Mondays

Jun 5, 2013

I created a report that runs each weekday morning, using data from the previous workday.

I have written code that saves the file into a LAN directory as "BEST CASH MM-DD-YYYY" with the variables being the previous day's date.

My problems is that when I run the report on Monday morning using Friday's data, of course it's including Sunday's date and not that previous Friday...

Here's the test code I'm working with right now; I'm using a folder on my desktop until I get the code right, then I'll change it to the proper LAN directory:

ChDir "C:UsersC700MDesktopTEST"
ActiveWorkbook.SaveAs Filename:= "C:UsersC700MDesktopTEST" & "BEST CASH " & Format(Date - 1, "mm-dd-yyyy"), FileFormat:= xlOpenXMLWorkbook, CreateBackup:=False

View 7 Replies View Related

Macro Works When The User Tabs Out The Cell

Aug 7, 2007

How do you add a macro to a cell that works wen the user tabs out the cell?

View 9 Replies View Related

Macro Works On Notebook Laptop But Not On Desk Top PC

Jun 6, 2006

I have this code working on my notebook:

Dim lastrow As Integer
Dim irow As Integer
lastrow = Workbooks("tmp").Worksheets("vRptMOMarkToHedgeFacilities"). Range("C65356").End(xlUp).Row
For irow = 2 To lastrow
Workbooks("tmp"). Sheets("vRptMOMarkToHedgeFacilities").Range("C" & irow).Copy
Windows("vlookupsheet.05.01.06.xls").Activate
Sheets("new stuff").Activate
Range("D" & irow + 1).Select
ActiveSheet.Paste
Next irow
Range("D1").Select

but it does not work on my desktop. For some reason when I go and execute the macro it gives me a "Run-time error '9' - Subscript out of range"

View 5 Replies View Related

2007 Macro Relative References Works On Only One Workbook

Oct 8, 2009

In Excel 2007 I am creating a macro with the "relative references" setting turned on. I want to repeat some tasks like: go to column A, sort, hide columns B thru F, hide columns H & I, return to column A.

Every time I try to create this macro by capturing key strokes, it inserts the workbook / worksheet name in the macro! Kinda defeats the ability to use it in any other workbook.

I am recording the macro in the PERSONAL.XLSX workbook. I have other macros that successfully perform in any workbook they are used in . . . but today I can't create one that doesn't incorporate the name of the original sheet it was recorded in.

View 12 Replies View Related







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