473,327 Members | 1,952 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

run-time error '1004' method 'range' of object '_global' failed

3
I have a problem.
The error in subject appear when i run the macro
Can u tell me why

Expand|Select|Wrap|Line Numbers
  1.  
  2.         Case "CENTRALIZATOR SURVEY"
  3.                 Dim SHT As Object
  4.                 Set SHT = Application.ThisWorkbook.Sheets("CENTRALIZATOR SURVEY")
  5.                 SHT.Cells(10, 1) = UCase(n)
  6.                 If IsEmpty(SHT.Cells(11, 1)) = False Then
  7.                 Do
  8.                     Range(SHT.Cells(11, 1), Cells(11, 8)).Select
  9.                     Selection.EntireRow.Delete
  10.                     Set SHT = Nothing
  11.                 Loop Until IsEmpty(SHT.Cells(11, 1))
  12.             End If
  13.                 nr_crt = 0
  14.                 suma = 0
  15.                 For i = 5 To 184
  16.                     For j = 3 To 6
  17.                         Select Case ThisWorkbook.Sheets("RAPORT ZILNIC").Cells(i, j).Value
  18.                             Case "SURVEY S1"
  19.                                 Set SHT = Application.ThisWorkbook.Sheets("CENTRALIZATOR SURVEY")
  20.                                 nr_crt = nr_crt + 1
  21.                                 suma = suma + 5
  22.                                 For k = 10 To 10 + nr_crt
  23.                                     If ThisWorkbook.Sheets("RAPORT ZILNIC").Cells(1, 3).Value = ThisWorkbook.Sheets("CENTRALIZATOR SURVEY").Cells(k, 1).Value Then
  24.                                         Range(SHT.Cells(k + nr_crt, 1), Cells(k + nr_crt, 8)).Select
  25.                                         Selection.EntireRow.Copy
  26.                                         Selection.Insert
  27.                                         Application.CutCopyMode = False
  28.                                         SHT.Cells(k + nr_crt, 1).Value = nr_crt
  29.                                         SHT.Cells(k + nr_crt, 2).Value = ThisWorkbook.Sheets("RAPORT ZILNIC").Cells(i, j + 1).Value
  30.                                         SHT.Cells(k + nr_crt, 3).Value = ThisWorkbook.Sheets("RAPORT ZILNIC").Cells(i, j + 2).Value
  31.                                         SHT.Cells(k + nr_crt, 4).Value = ThisWorkbook.Sheets("RAPORT ZILNIC").Cells(i, j + 3).Value
  32.                                         SHT.Cells(k + nr_crt, 5).Value = "S1"
  33.                                     End If
  34.  
  35.                                 Next k
  36.                                 Set SHT = Nothing
  37.                             Case "SURVEY S2"
  38.                                 Set SHT = Application.ThisWorkbook.Sheets("CENTRALIZATOR SURVEY")
  39.                                 nr_crt = nr_crt + 1
  40.                                 suma = suma + 40
  41.                                 For k = 10 To 10 + nr_crt
  42.                                     If ThisWorkbook.Sheets("RAPORT ZILNIC").Cells(1, 3).Value = SHT.Cells(k, 1).Value Then
  43.                                         Range(SHT.Cells(k + nr_crt, 1), Cells(k + nr_crt, 8)).Select
  44.                                         Selection.EntireRow.Copy
  45.                                         Selection.Insert
  46.                                         Application.CutCopyMode = False
  47.                                         SHT.Cells(k + nr_crt, 1).Value = nr_crt
  48.                                         SHT.Cells(k + nr_crt, 2).Value = ThisWorkbook.Sheets("RAPORT ZILNIC").Cells(i, j + 1).Value
  49.                                         SHT.Cells(k + nr_crt, 3).Value = ThisWorkbook.Sheets("RAPORT ZILNIC").Cells(i, j + 2).Value
  50.                                         SHT.Cells(k + nr_crt, 4).Value = ThisWorkbook.Sheets("RAPORT ZILNIC").Cells(i, j + 3).Value
  51.                                         SHT.Cells(k + nr_crt, 5).Value = "S2"
  52.                                     End If
  53.  
  54.                                 Next k
  55.                                 Set SHT = Nothing
  56.                             Case "ALTE SERVICII"
  57.                                 Set SHT = Application.ThisWorkbook.Sheets("CENTRALIZATOR SURVEY")
  58.                                 nr_crt = nr_crt + 1
  59.                                 suma = suma + 10
  60.                                 For k = 10 To 10 + nr_crt
  61.                                     If ThisWorkbook.Sheets("RAPORT ZILNIC").Cells(1, 3).Value = SHT.Cells(k, 1).Value Then
  62.                                         Range(SHT.Cells(k + nr_crt, 1), Cells(k + nr_crt, 8)).Select
  63.                                         Selection.EntireRow.Copy
  64.                                         Selection.Insert
  65.                                         Application.CutCopyMode = False
  66.                                         SHT.Cells(k + nr_crt, 1).Value = nr_crt
  67.                                         SHT.Cells(k + nr_crt, 2).Value = ThisWorkbook.Sheets("RAPORT ZILNIC").Cells(i, j + 1).Value
  68.                                         SHT.Cells(k + nr_crt, 3).Value = ThisWorkbook.Sheets("RAPORT ZILNIC").Cells(i, j + 2).Value
  69.                                         SHT.Cells(k + nr_crt, 4).Value = ThisWorkbook.Sheets("RAPORT ZILNIC").Cells(i, j + 3).Value
  70.                                         SHT.Cells(k + nr_crt, 5).Value = "A"
  71.                                     End If
  72.  
  73.                                 Next k
  74.                                 Set SHT = Nothing
  75.                             Case "RECUPERARE"
  76.                                 Set SHT = Application.ThisWorkbook.Sheets("CENTRALIZATOR SURVEY")
  77.                                 nr_crt = nr_crt + 1
  78.                                 suma = suma + 20
  79.                                 For k = 10 To 10 + nr_crt
  80.                                     If ThisWorkbook.Sheets("RAPORT ZILNIC").Cells(1, 3).Value = SHT.Cells(k, 1).Value Then
  81.                                         Range(SHT.Cells(k + nr_crt, 1), Cells(k + nr_crt, 8)).Select
  82.                                         Selection.EntireRow.Copy
  83.                                         Selection.Insert
  84.                                         Application.CutCopyMode = False
  85.                                         SHT.Cells(k + nr_crt, 1).Value = nr_crt
  86.                                         SHT.Cells(k + nr_crt, 2).Value = ThisWorkbook.Sheets("RAPORT ZILNIC").Cells(i, j + 1).Value
  87.                                         SHT.Cells(k + nr_crt, 3).Value = ThisWorkbook.Sheets("RAPORT ZILNIC").Cells(i, j + 2).Value
  88.                                         SHT.Cells(k + nr_crt, 4).Value = ThisWorkbook.Sheets("RAPORT ZILNIC").Cells(i, j + 3).Value
  89.                                         SHT.Cells(k + nr_crt, 5).Value = "D"
  90.  
  91.                                     End If
  92.  
  93.                                 Next k
  94.                                 Set SHT = Nothing
  95.                         End Select
  96.                 Set SHT = Application.ThisWorkbook.Sheets("CENTRALIZATOR SURVEY")
  97.                 SHT.Cells(nr_crt + 13, 6).Value = suma
  98.                 Set SHT = Nothing
  99.                 Next j
  100.                 Next i
  101.  
Dec 18 '06 #1
4 7125
Killer42
8,435 Expert 8TB
I have a problem.
The error in subject appear when i run the macro
Can u tell me why

Expand|Select|Wrap|Line Numbers
  1. Case "CENTRALIZATOR SURVEY"
  2.   Dim SHT As Object
  3.   Set SHT = Application.ThisWorkbook.Sheets("CENTRALIZATOR SURVEY")
  4.   SHT.Cells(10, 1) = UCase(n)
  5.   If IsEmpty(SHT.Cells(11, 1)) = False Then
  6.     Do
  7.       Range(SHT.Cells(11, 1), Cells(11, 8)).Select
  8.       Selection.EntireRow.Delete
  9.       Set SHT = Nothing
  10.     Loop Until IsEmpty(SHT.Cells(11, 1))
  11.   End If
  12.   nr_crt = 0
  13.   suma = 0
  14.   For i = 5 To 184
  15.     For j = 3 To 6
  16.       Select Case ThisWorkbook.Sheets("RAPORT ZILNIC").Cells(i, j).Value
  17.         Case "SURVEY S1"
  18.           Set SHT = Application.ThisWorkbook.Sheets("CENTRALIZATOR SURVEY")
  19.           nr_crt = nr_crt + 1
  20.           suma = suma + 5
  21.           For k = 10 To 10 + nr_crt
  22.             If ThisWorkbook.Sheets("RAPORT ZILNIC").Cells(1, 3).Value = ThisWorkbook.Sheets("CENTRALIZATOR SURVEY").Cells(k, 1).Value Then
  23.               Range(SHT.Cells(k + nr_crt, 1), Cells(k + nr_crt, 8)).Select
  24.               Selection.EntireRow.Copy
  25.               Selection.Insert
  26.               Application.CutCopyMode = False
  27.               SHT.Cells(k + nr_crt, 1).Value = nr_crt
  28.               SHT.Cells(k + nr_crt, 2).Value = ThisWorkbook.Sheets("RAPORT ZILNIC").Cells(i, j + 1).Value
  29.               SHT.Cells(k + nr_crt, 3).Value = ThisWorkbook.Sheets("RAPORT ZILNIC").Cells(i, j + 2).Value
  30.               SHT.Cells(k + nr_crt, 4).Value = ThisWorkbook.Sheets("RAPORT ZILNIC").Cells(i, j + 3).Value
  31.               SHT.Cells(k + nr_crt, 5).Value = "S1"
  32.             End If
  33.           Next k
  34.           Set SHT = Nothing
  35.         Case "SURVEY S2"
  36.           Set SHT = Application.ThisWorkbook.Sheets("CENTRALIZATOR SURVEY")
  37.           nr_crt = nr_crt + 1
  38.           suma = suma + 40
  39.           For k = 10 To 10 + nr_crt
  40.             If ThisWorkbook.Sheets("RAPORT ZILNIC").Cells(1, 3).Value = SHT.Cells(k, 1).Value Then
  41.               Range(SHT.Cells(k + nr_crt, 1), Cells(k + nr_crt, 8)).Select
  42.               Selection.EntireRow.Copy
  43.               Selection.Insert
  44.               Application.CutCopyMode = False
  45.               SHT.Cells(k + nr_crt, 1).Value = nr_crt
  46.               SHT.Cells(k + nr_crt, 2).Value = ThisWorkbook.Sheets("RAPORT ZILNIC").Cells(i, j + 1).Value
  47.               SHT.Cells(k + nr_crt, 3).Value = ThisWorkbook.Sheets("RAPORT ZILNIC").Cells(i, j + 2).Value
  48.               SHT.Cells(k + nr_crt, 4).Value = ThisWorkbook.Sheets("RAPORT ZILNIC").Cells(i, j + 3).Value
  49.               SHT.Cells(k + nr_crt, 5).Value = "S2"
  50.             End If
  51.           Next k
  52.           Set SHT = Nothing
  53.         Case "ALTE SERVICII"
  54.           Set SHT = Application.ThisWorkbook.Sheets("CENTRALIZATOR SURVEY")
  55.           nr_crt = nr_crt + 1
  56.           suma = suma + 10
  57.           For k = 10 To 10 + nr_crt
  58.             If ThisWorkbook.Sheets("RAPORT ZILNIC").Cells(1, 3).Value = SHT.Cells(k, 1).Value Then
  59.               Range(SHT.Cells(k + nr_crt, 1), Cells(k + nr_crt, 8)).Select
  60.               Selection.EntireRow.Copy
  61.               Selection.Insert
  62.               Application.CutCopyMode = False
  63.               SHT.Cells(k + nr_crt, 1).Value = nr_crt
  64.               SHT.Cells(k + nr_crt, 2).Value = ThisWorkbook.Sheets("RAPORT ZILNIC").Cells(i, j + 1).Value
  65.               SHT.Cells(k + nr_crt, 3).Value = ThisWorkbook.Sheets("RAPORT ZILNIC").Cells(i, j + 2).Value
  66.               SHT.Cells(k + nr_crt, 4).Value = ThisWorkbook.Sheets("RAPORT ZILNIC").Cells(i, j + 3).Value
  67.               SHT.Cells(k + nr_crt, 5).Value = "A"
  68.             End If
  69.           Next k
  70.           Set SHT = Nothing
  71.         Case "RECUPERARE"
  72.           Set SHT = Application.ThisWorkbook.Sheets("CENTRALIZATOR SURVEY")
  73.           nr_crt = nr_crt + 1
  74.           suma = suma + 20
  75.           For k = 10 To 10 + nr_crt
  76.             If ThisWorkbook.Sheets("RAPORT ZILNIC").Cells(1, 3).Value = SHT.Cells(k, 1).Value Then
  77.               Range(SHT.Cells(k + nr_crt, 1), Cells(k + nr_crt, 8)).Select
  78.               Selection.EntireRow.Copy
  79.               Selection.Insert
  80.               Application.CutCopyMode = False
  81.               SHT.Cells(k + nr_crt, 1).Value = nr_crt
  82.               SHT.Cells(k + nr_crt, 2).Value = ThisWorkbook.Sheets("RAPORT ZILNIC").Cells(i, j + 1).Value
  83.               SHT.Cells(k + nr_crt, 3).Value = ThisWorkbook.Sheets("RAPORT ZILNIC").Cells(i, j + 2).Value
  84.               SHT.Cells(k + nr_crt, 4).Value = ThisWorkbook.Sheets("RAPORT ZILNIC").Cells(i, j + 3).Value
  85.               SHT.Cells(k + nr_crt, 5).Value = "D"
  86.             End If
  87.           Next k
  88.           Set SHT = Nothing
  89.       End Select
  90.       Set SHT = Application.ThisWorkbook.Sheets("CENTRALIZATOR SURVEY")
  91.       SHT.Cells(nr_crt + 13, 6).Value = suma
  92.       Set SHT = Nothing
  93.     Next j
  94.   Next i
Hi.
I've put [c o d e] tags around your code, as it aids readability. I also reduced thge indenting a bit, just to reduce sideways scrolling a little here on TheScripts. Sorry about that.

Could you please give us a hint as to where in this code the error occurs?

Also, where is the code located? If it's in a module rather than a worksheet, perhaps it doesn't know what to apply the Range method to.
Dec 19 '06 #2
dilau
3
the error appear in first range at case "centralizator survey" and the same in case "centralizator instalari"
Dec 19 '06 #3
dilau
3
and YES is in a module
Dec 19 '06 #4
Killer42
8,435 Expert 8TB
and YES is in a module
Maybe you need to refer to CurrentSheet.Range or something? How is the Range function supposed to know what object sheet you're referring to?
Dec 20 '06 #5

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

Similar topics

1
by: James | last post by:
Hi, I would like to run a custom script on a linux box via a button on a php page (php webpage hosted on the same linux box). Is this possible? If so , can you give me a pointer in the right...
3
by: leroybt.rm | last post by:
Can someone tell me how to run a script from a interactive shell I type the following: >>>python filename >>>python filename.py >>>run filename >>>run filename.py >>>/run filename >>>/run...
4
by: Ed | last post by:
Hello, I took a course in asp about 2 years ago and I was practicing with IIS 5.0. Then I put it down for a while. Now trying to get back to it. I can't run asp files from subdirectories of...
6
by: orekin | last post by:
Hi There I have been trying to come to grips with Application.Run(), Application.Exit() and the Message Pump and I would really appreciate some feedback on the following questions .. There are...
9
by: shank | last post by:
What is the proper syntax to run this command line in ASP? wzzip.exe File.zip File.txt thanks
8
by: David Thielen | last post by:
Hi; In our setup program how do I determine if I need to run "aspnet_regiis –i" and if so, is there an API I can calll rather than finding that program on the user's disk and calling it? --...
26
by: Chief | last post by:
Hello i would like to know which syntax do i have to use in order to make a program run other *.exe program and also how to put inputs in it for example i want to to make a program that run...
3
by: traceable1 | last post by:
Is there a way I can set up a SQL script to run when the instance starts up? SQL Server 2005 SP2 thanks!
8
by: Sean DiZazzo | last post by:
Is there something special you have to do to get a wxPython app to run remotely under xwindows? My Tkinter apps always automatically work that way, so I was surprised to even be confronted with...
16
by: maya | last post by:
hi, this is very annoying.. this is on IE7/Vista.. whenever I load a pg with JavaScript on it IE refuses to run the JavaScript (I'm talking about JavaScript written BY ME....;) and the weird...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.