ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Run-Time error '1004' (https://www.excelbanter.com/excel-programming/275534-run-time-error-1004-a.html)

Bob[_33_]

Run-Time error '1004'
 
Below is the sub that I have written. Can anyone tell me
why I am getting this error?:

"Run-Time error '1004':
Method 'Range" of object '_Global" failed

It's giving me the error on this line:
Range(rng1, "1:1").EntireRow.Select

Here's the Sub:
#########################
General

Dim Vertrng As Range, Plotrng As Range, rng1 As Range,
rng2 As Range, Arng As Range, POBrng As Range, rng3 As
Range
Dim cell As Range
_____________________________
Sub CogoPC_DataConversion()

Set Vertrng = Range(Cells(1, 1), Cells(Rows.Count, 1).End
(xlUp))
For Each cell In Vertrng
If cell.Value = "*VERTICAL" And rng1 Is Nothing Then
Set rng1 = cell
Exit For
End If
Next

Range(rng1, "1:1").EntireRow.Select
Selection.ClearContents

Call Step2
End Sub
##########################

Keith Willshaw

Run-Time error '1004'
 

"Bob" wrote in message
...
Below is the sub that I have written. Can anyone tell me
why I am getting this error?:


If it runs through the for next loop and doesnt find
the value "*VERTICAL" then rng1 will be unset
and the selection wil fail

Try

If Not rng1 Is Nothing Then
Range(rng1, "1:1").EntireRow.Select
Selection.ClearContents
End If

Keith



Tom Ogilvy

Run-Time error '1004'
 
The obvious answer is that no cell in Vertrng passes the test

If cell.Value = "*VERTICAL"


Does the cell actually contain the string *VERTICAL or are you trying to
use * as a wild card. If a wildcard, that doesn't work.

for a wildcard use either Instr or Like


Activeworkbook.BuiltinDocumentProperties("Company" ).Value = "My Company"
? Activeworkbook.BuiltinDocumentProperties("Company" ).Value
My Company
Worksheets("Sheet1").Range("9:9").Value=Worksheets ("Sheet2").Range("15:15").
Value

sStr = "My Vertical Wall"
? sSTr = "*Vertical"
False
? sStr like "*Vertical"
False
? sStr like "*Vertical*"
True
? instr(1,sStr,"vertical",vbTextCompare)
4

Instr returns the postion within sStr where the substring is found. A zero
result indicates it isn't included.

Like is case sensitive, but you could remove that with

Ucase(sStr) like "*VERTICAL*"

--
Regards,
Tom Ogilvy


"Bob" wrote in message
...
Below is the sub that I have written. Can anyone tell me
why I am getting this error?:

"Run-Time error '1004':
Method 'Range" of object '_Global" failed

It's giving me the error on this line:
Range(rng1, "1:1").EntireRow.Select

Here's the Sub:
#########################
General

Dim Vertrng As Range, Plotrng As Range, rng1 As Range,
rng2 As Range, Arng As Range, POBrng As Range, rng3 As
Range
Dim cell As Range
_____________________________
Sub CogoPC_DataConversion()

Set Vertrng = Range(Cells(1, 1), Cells(Rows.Count, 1).End
(xlUp))
For Each cell In Vertrng
If cell.Value = "*VERTICAL" And rng1 Is Nothing Then
Set rng1 = cell
Exit For
End If
Next

Range(rng1, "1:1").EntireRow.Select
Selection.ClearContents

Call Step2
End Sub
##########################





All times are GMT +1. The time now is 02:15 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com