473,480 Members | 1,975 Online
Bytes | Software Development & Data Engineering Community
Create 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.paste 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 1744
NeoPa
32,556 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_Change() event procedure I noticed you used Range(Target.Address). 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.CutCopyMode = 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
10780
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...
6
19218
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,...
0
2342
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...
0
5039
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...
3
15756
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...
2
6598
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...
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...
8
13075
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...
0
1368
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...
1
2590
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...
0
7043
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,...
0
7081
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...
1
6737
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...
0
5336
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4481
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2995
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...
0
2984
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1300
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 ...
1
563
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.