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
ADVERTISEMENT
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
May 21, 2009
How do I disable a step in a macro without having to delete it?
View 3 Replies
View Related
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
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
Aug 11, 2012
I have a layout something like the following:
A1
A2
A3
[Code]....
Where each (i.e., A1) represents a location. I have tried to use a coordinate system but this will not work for the back-to-back locations. (Assuming each location is 2 feet wide, For example A1 to C1 is 4 feet apart, not 2 feet (as Euclidean or rectilinear would calculate it as).
Would there be a way to incorporate an if statement for those locations that are back-to-back? As a rectilinear distance calculation would work as long as the locations are not part of the same "block".
Ultimately I am looking to have a matrix which contains all the distances between each location:
A1
A2
A3
B1
[Code].....
View 4 Replies
View Related
Aug 31, 2007
macro which can paste the value from A1, to another B1 and when A1 is edited again, pasted it in B2. This will probably go on and on until B30. I have tried the if else then in Macro, and even the if elseif, but both don't go futher than B2. E.G A1=1 B1=1 A1=4 B2=4 A1=3 then nothing happens to B3. If there is a way to make this work, it will be great. The way i am tryin to get it is to have =if(B1="","",1) for each cell from C1:30 and with C31 the formula "=count(C1:C30)+1". Then i formated C31 to a custom and make it so that before numbers, there is an B. This means that if B1,2,3 and 4 and numbers in them, then C31 will read B5. That will be the cell i want my next record to go. I would prefer it if there is just a code that i can enter that will go to the next cell when it knows the current cell has a digit in it but if i have to, the count way will do,
View 9 Replies
View Related
Jul 13, 2009
I need to copy a changing source cell, paste its value into another specific cell (always the same), and then return to the source cell for continued action (ie range selection, copy & value paste, which I can code).
This action is then followed in the next cell to the R of the first cell copied, etc to end of data. I can code the move to the R.
How do I return to the source cells as part of a loop?
Specific notes included in attached - I hope I've explained it clearly.
View 12 Replies
View Related
Aug 8, 2008
A little context:
Searching this forum for "sleep", "delay" or "animation" will bring up a host of threads referring to the kernel32 function, sleep. This is a great way of putting small delays into code without the potential "synchronisation" problems of application .ontime calls or the "ugliness" of multiple-thousands looping.
My question:
When I call sleep (with values in the hundreds of milliseconds) several times in a macro, it seems like the computer just "gives up" screen updating after a few (maybe 50) iterations. The macro still takes the time I'd expect, accounting for all the sleeps, but it stops showing the intermediate steps and just shows the end result after the macro ends.
Is this something to do with RAM? Is there something about calling this command too much or too frequently that kernel32 doesn't like? Is my computer a useless bag of nails and spit?
View 3 Replies
View Related
May 22, 2013
I have a macro running in a workbook that gathers some data (a date, a string and a few arrays). Towards the end of this macro, I need it to open another workbook and run a macro that sits in this other workbook, using the data from the first workbook. I then need it to return some results (several integers) back to the first macro to be pasted into the first workbook.
I gather that I can't use 'Call' as the second macro is in another workbook.
I've found that I can use Application.Run but I'm unsure how to carry variables back and forth using this.
How to move the variables between macros / workbooks using the Application.Run option, or maybe another way of doing things?
View 1 Replies
View Related
Mar 26, 2009
I want to have a small button at the top of the sheet that when pressed, will automatically reset all filtered autofilters back to show all.
View 9 Replies
View Related
Jun 28, 2012
let's say I run a macro from a button on sheet 3, macro process on sheet 10. Is there a way that the macro would automatically go back to sheet 3? Like a "Back" button on IE. I can't code Sheets("sheet 3").Select because I want it to do the same thing on sheet 4,5,6...
View 3 Replies
View Related
Sep 27, 2012
I am about to write a small macro to do a iteration calculation. I would like though for the user to select me a cell so that the macro uses the value in that cell to start calculations. Now, what I think would be the problem is how do I code a "time" or notice an action such as clicking in a cell to continue with the macro.
Would it be by inserting a pause in the code of a certain time so that gives the user time to click and wait for the code to start? If so, how would much time is enough? Is there another thing that could restart the code such as "noticing a click in a cell" command in VBA?
View 1 Replies
View Related
Feb 26, 2014
I am trying to create a macro, that ultimately does the reverse of one written a while back.
I have created a macro that exports "Roster_Data" to "envision_Roster" in .csv style formatting. What I want to achieve is reverse engineer the macro to return the data back to a similar state.
I am trying to transpose column D into rows that correspond with dates in column c in a sheet called "OutputView" this in essence is similar if not exactly the same as the original worksheet "Roster_Data"
I have split the macro I am working on into three separate modules.
Module 1 - Initial Export of "Roster_Data" to "envision_Roster"
Module 2 - Format and output worksheet to find MAX date and MIN date and produce top rows of data
Module 3 - Analyse, Undertake Logical Tests of data, and transpose to suit (Replicate the initial "Roster_Data" view)
I'm having trouble visioning this altogether so I've been starting with basic code to output basic stuff, but I still can't relate this back to my data.
[Code]....
View 2 Replies
View Related
Apr 26, 2006
I have some code that, although works fine in Excel 2003, does not in Excel 1997. I receive this error when I try running it:
COMPILE ERROR:
NAMED ARGUMENT NOT FOUND
Sub HPVAL()
Dim r As Range, myStr As String
myStr = "HP"
Set r = Cells. Find(What:=myStr, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False)
If Not r Is Nothing Then
r = r.Value
While Not r Is Nothing
Set r = Cells.FindNext(r)
If Not r Is Nothing Then
r = r.Value
End If
Wend
End If
End Sub
It looks like Excel is getting hung up on the "SearchFormat:=" portion of the code.
View 2 Replies
View Related
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
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
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
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
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
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
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
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
Mar 11, 2008
Is there a way to loop through a range of numbers, pick the first 24 columns, do some kind of caclulation for each column and row, the start again on column 25 for another 24 columns, perform the same calculation, go to the next set of 24 columns, etc?
I have tried using, for example, AVERAGE(OFFSET(range,0,0,24,24) and that correctly returns the average for the first 24 columns (range being the range of data I am using like D366:HK389). However, unless I manually change the starting column for the next set, it doesn't return the correct result. I have attached a sample data spreadsheet. There are 9 Locations in the spreadsheet where each Location contains a 24x24 matrix.
View 4 Replies
View Related
Apr 4, 2013
I am having trouble with the code for this stepped scale rebate structure
$0 TO $50,000 NET PURCHASES=NO REBATE ISSUED
$50,001 TO $150,000=5% OF NET PURCHASES
$150,001 TO $1,000,000=8% OF NET PURCHASES
$1,000,001 TO $2,000,000=9% OF NET PURCHASES
$2,000,001 AND OVER=10% OF NET PURCHASES
I have the forumula for retro active to 50,000
=IF(O77<50001,"0",IF(O77<=150000,O77*5%,IF(O77<=1000000,O77*8%,IF(O77<=2000000,O77*9%,IF(O77>2000001,O77*10%,)))))
If the customer did 2.5 million. I need a formula that will multiply the first 150,000 by 5%, the next 849,999 @ 8%, the next 999,999 @ 9%, and the remaining 500,000 2 10%. I was thinking of using a min/max function.
View 6 Replies
View Related
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
Apr 27, 2009
My vb code currently creates a new sheet via "Sheets.add". This new sheet has the default name of "sheet1" which I rename as "tempSheet". I then populate tempSheet with data, save as a CVS file and then I remove tempSheet.
If I stay in my workbook and try to execute the code again, the default name of the sheet it now creates is "sheet2" and not "sheet1" - this is a problem becuase my code is trying to rename "sheet1" "tempSheet" and of course it cant.
View 3 Replies
View Related
Oct 8, 2011
The following code was working for me and now no longer works. Also, it works when I step through but not when I run it normally (it stops at the line imeediately following this line:
OrigWB.Sheets("PP&E").Move after:=DestWB.Sheets(DestWB.Sheets.Count) ) regardless of what code it is - even if it is only a message box.
The error message is code execution has been interupted.
******************
Sub PPEMerge()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.StatusBar = "Merging..."
'retrieve source docs:
'PP&E sheets from sec packages
'system beginning and ending balances
[code]....
View 1 Replies
View Related
Sep 7, 2006
I am having trouble with the code for this stepped scale commission structure.
Net Service
$1,1400
Step Scale Comm. %
$0-500 40%
$500-750 45%
$750-1000 47%
$1000-9999.99 50%
Final Commission Paid $ ?
View 7 Replies
View Related
Jan 15, 2007
I have created a custom Command Bar called "My New Bar"
How can I step through each button in that bar to read the assigned macro names or the Caption names
View 9 Replies
View Related