Run Time 1004 Error

ipon70

Board Regular
Joined
May 8, 2013
Messages
86
Office Version
  1. 2016
Platform
  1. Windows
I have a piece of code

Sub Fix_Page()
Dim ws As Worksheet
Dim range1 As Range, rng As Range
Set ws = ThisWorkbook.Worksheets("Input")
Set rng4 = ws.Range("G8")
With rng4.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _
Formula1:="=Org"
End With
End Sub

The above code works for most of the cells I am trying to use it for except this one. Because at the point this runs nothing above it has been selected "technically" this cell does "resolve to an error" so you would just normally say "continue". and it does work once selections above it are made. How do I tell VBA "yes I know its an error right now but it will work later" and have it continue with the list and formula for that cell.

Hope that makes sense.

Thanks in advance.
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
If it's just an alert, you can try to use the following:
VBA Code:
Application.DisplayAlerts = False
' Code that causes the alert here
Application.DisplayAlerts = True
 
Upvote 0
If it's just an alert, you can try to use the following:
VBA Code:
Application.DisplayAlerts = False
' Code that causes the alert here
Application.DisplayAlerts = True
So the error is from VBA, but the issue is with the "Name Manager" and the name listed above. Because section 1,2, and 3 haven't been filled out a before this is put in, VBA thinks its an error.
And I did try this and it didn't work
 
Upvote 0
Yes, sorry, you said 1004 error. I'm just having trouble figuring out what's happening in the code, and I don't know what Section 1, 2, and 3 are for you. Could you give us a screenshot of the sheet and point out where the error is happening?
 
Upvote 0
If you are setting the data validation before you have set up the range name "Org" then you would certainly get that error but why would you do that ?
 
Upvote 0
If you are setting the data validation before you have set up the range name "Org" then you would certainly get that error but why would you do that ?
So people are copying and pasting things and that messes up some of the cells that we allow manual typing. Every once in awhile for whatever reason another cell with a validated drop down list will get mess up randomly. The code for that works. But it doesn't have anything to choose or pull the list from until it knows what state, city, and county you are in, then it knows what "orgs" to offer. Because the State, city, and county aren't picked when you press the "fix it" button, it thinks theres an errors but there really isn't. So I need the code to accept that the =Org is ok it just appears broken at the moment.
In the name manager the name Org refers to this code "=OFFSET(Setup!$G$2,1,MATCH(Input!$G$6,Setup!$G$2:$AE$2,0)-1,COUNTA(OFFSET(Setup!$G$2,1,MATCH(Input!$G$6,Setup!$G$2:$AE$2,0)-1,40,1),1))"
In the picture below is what I get when I press the VBA button and what I get when I do it manually. But I promise the Source is good it just doesn't work until things above it are picked.
 

Attachments

  • cap1.PNG
    cap1.PNG
    35 KB · Views: 4
  • cap2.PNG
    cap2.PNG
    4.1 KB · Views: 3
Upvote 0
Yes, sorry, you said 1004 error. I'm just having trouble figuring out what's happening in the code, and I don't know what Section 1, 2, and 3 are for you. Could you give us a screenshot of the sheet and point out where the error is happening?
So people are copying and pasting things and that messes up some of the cells that we allow manual typing. Every once in awhile for whatever reason another cell with a validated drop down list will get mess up randomly. The code for that works. But it doesn't have anything to choose or pull the list from until it knows what state, city, and county you are in, then it knows what "orgs" to offer. Because the State, city, and county aren't picked when you press the "fix it" button, it thinks theres an errors but there really isn't. So I need the code to accept that the =Org is ok it just appears broken at the moment.
In the name manager the name Org refers to this code "=OFFSET(Setup!$G$2,1,MATCH(Input!$G$6,Setup!$G$2:$AE$2,0)-1,COUNTA(OFFSET(Setup!$G$2,1,MATCH(Input!$G$6,Setup!$G$2:$AE$2,0)-1,40,1),1))"
In the picture below is what I get when I press the VBA button and what I get when I do it manually. But I promise the Source is good it just doesn't work until things above it are picked.
 

Attachments

  • cap1.PNG
    cap1.PNG
    35 KB · Views: 1
  • cap2.PNG
    cap2.PNG
    4.1 KB · Views: 2
Upvote 0
Could you fill out those cells with some standard State, City, and County info, then add the validation, then remove the State, City and County info afterward?
 
Upvote 0

Forum statistics

Threads
1,224,813
Messages
6,181,117
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top