473,598 Members | 2,916 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Excel VBA: Runtime Error in Every Second Run

1 New Member
Hi,

I have a problem. I have created macro which copies text from one cell and paste it to other cell in other sheet.This macro is called from other macro so that if you change any cell in specific range then it will call this macro.

Now it works every second time but when does not run time error 1004 occurs. it seems that error occurs during activesheet.pas te command. What should i do?

Here's the mmacro which calls other macro when specific cells are changed :
Expand|Select|Wrap|Line Numbers
  1. Private Sub Worksheet_Change(ByVal Target As Range)
  2.     Dim KeyCells As Range
  3.  
  4.     Set KeyCells = Range("AnalysoitavatS[Note]")
  5.  
  6. If Not Application.Intersect(KeyCells, Range(Target.Address)) _
  7.            Is Nothing Then
  8.  
  9. Call kopioi_note
  10.  
  11. End If
  12. End Sub
And here's the macro which does the copying :
Expand|Select|Wrap|Line Numbers
  1. ActiveCell.Offset(-1, 0).Copy
  2. ActiveCell.Offset(-1, -9).Select
  3.     Value2 = Selection
  4.      Sheets("KAIKKI HUOLLOT").Select
  5.       ActiveSheet.Unprotect Password:="1"
  6.     Range("MASTER[Order]").Select
  7.     Selection.Find(What:=Value2, After:=ActiveCell, LookIn:=xlFormulas, _
  8.         Lookat:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
  9.         MatchCase:=False, SearchFormat:=False).Activate
  10.     ActiveCell.Offset(0, 21).Activate
  11.     ActiveSheet.Paste
  12.     ActiveSheet.Protect Password:="1"
  13.     Sheets("ANALYSOINTI").Select
  14.     Range("A3").Select
Nov 1 '19 #1
1 1767
NeoPa
32,566 Recognized Expert Moderator MVP
Hi ingengör.

Welcome to Bytes.com.

ingengör:
And here's the macro which does the copying :
Unfortunately that's only part of the procedure as it doesn't include the definition - either of the procedure itself or any of the variables you're using. A bit like working with a blindfold on. It would also be helpful to share the error message rather than just the number.

Otherwise this question is well asked and as a first time is pretty decent. Well done.

I'll add comments as they occur to me. If I cannot necessarily solve the problem I can at least raise issues for you to think about.

I'll start by saying that this is clearly an Excel question rather than Access. This is fine, but people need to understand that so I'll update the title to make that clear. This is, after all, an Access forum.

From your Worksheet_Chang e() event procedure I noticed you used Range(Target.Ad dress). That's saying :
Take a Range, convert it to the matching address, then convert it back into a Range again. IE. It leaves you where you started with Target. A bit strange but unlikely to be the cause of any problems.

Congratulations on using .Find() in such a clear way. Named arguments make it so much easier to follow and harder to get wrong. Also using the line continuation character (_) makes it so much easier to read & follow.

As far as what's causing the problems on alternate runs goes I can't see anything obvious. It doesn't help that I have very little idea of what's in your Workbook of course, but I can suggest you check that where the Selection of Cells and Worksheets are after the code finishes running the first time is not causing the issues when you run it the next time. Another thing to check is whether or not there's anything on the Clipboard. I see no code to Cut or Copy, nor do I see anything to clear the Clipboard after the .Paste (Application.Cut CopyMode = False).

Let us know if any of this helps.
Nov 2 '19 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

10
10805
by: | last post by:
I am accessing the same error-containing ASP page on an ISP server using w2k IE6 but with different effect. On the first computer I get several line of HTML outputed by ASP, shown correctly by the browser, followed by a descriptive error message: Microsoft VBScript runtime error '800a000b' Division by zero followed by the number of the error-making line
6
19240
by: Dan Roberts | last post by:
I am running some off-the-shelf software that is written in ASP, which uses JScript to generate dynamic content within HTML forms. There are several ASP pages which are partially rendering to IE, but stop midway through with an error embeded in the page: "Microsoft JScript runtime error '800a138f' 'undefined' is null or not an object". The software package has a large install base with no other customer having this problem. I also have...
0
2352
by: Mark C | last post by:
All, I have used Excel automation many times in the past without error until now. My machine has both Access 97 and XP installed but this code is written in 97 and I am using Excel XP. The code below is running in my database: Dim exl As Excel.Application Set exl = New Excel.Application exl.Workbooks.Open ("C:\Test\ Listing.xls")
0
5063
by: Jamey | last post by:
I perused old posts for an answer to this for at least an hour, and I've found a work-around, but no definitive answer. Synopsis of the problem: On NotInList or ctl.Requery commands where a record has been deleted (or appended via SQL), Access returns Runtime error 2118 when you get to the Requery command which reads: 'You must save the current field before you run the Requery action.'
3
15777
by: bill_hounslow | last post by:
I'm trying to transfer data from one Sql Server into a table on another, using a simple INSERT query in an Access database with links to tables on both servers (the reasons for this are complicated but it IS the simplest solution, believe me). The 'Select' clause of the query works fine when run alone, but, when I run the INSERT query I get a Runtime Error 3167 Record Deleted. I get the error even when I'm the only person accessing...
2
6607
by: info | last post by:
I am pasting in a recordset from access to an excel sheet via VBA successfully. Then my routine copies a range of cells and pastes them into another range, this works fine every other time it runs. Every other run of the code it fails at the line Selection.Copy with a Runtime error 91:. I then run it again and it works fine. This is really puzzling me a snippet of my code is below. Any ideas? >>>>>>>>>>>>>>>>>>>>>>
6
539
by: mark | last post by:
I have an asp.net ecommerce web application on a remote web server. I'm using an Access database on the back end. I've notice a few strange things. When I mimic an multiple user environment by surfin it in multiple browsers simultaneously the site generates a generic runtime error after awhile. I'm thinking this has something to do with my access database and multiple connections. I'm using forms authentication with a login page. Is...
8
13090
by: g_man | last post by:
I am trying trap Runtime error 3022 (duplicates) in the click event of a command button that closes the form. I have code in the Form_Error event that does a good job of providing a more meaningful error message than the default. It works in every situation except when the user clicks the close button. I am using Me.Dirty=False to force a save but if there are duplicates I just get the standard Runtime 3022 error message. I am wondering...
0
1380
by: sankohar | last post by:
I have two vb projects.I am calling second project from first project.In first project i have added a reference of activex exe of second project. Now when i am running the first project in debug mode, i am able to debug second project also and its working fine. But if i run the first project exe directly, i am getting VB Runtime Error -" 2147217887 Multiple-step OLE DB operation" from my second project. In debug mode its works fine but in...
1
2611
by: kickergirl | last post by:
I recently created a database in Access 2000 that has been distributed to multiple people using various versions of Access. Each person is using it as a standalone database. The database has multiple forms that collect information on individual people. In fact there are 5 forms per person. The first and second form write data to the same table. The VBA code below is what happens when the user continues to the second form to enter more...
0
7894
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8284
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8392
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8046
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
3894
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3938
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2410
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1500
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1245
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.