I don't know what I am doing wrong....

rlink_23

Board Regular
Joined
Oct 30, 2015
Messages
149
I have used a code like this in a different part of my userform, To transfer info from a sheet to the userform. I have a list of Zipcodes in a sheet called ("Zips") in Column A is the actual Zip code, the State is in Column B, and City is Column C. What I am trying to do is when the Zip code is entered into TextBox ("Zipcode") It populates TextBox ("City") and TextBox ("State"). I have used a very similar code Elsewhere in my userform but this code WILL NOT work at all.. I know it is trying as it runs super super solw when I am typing in the TextBox ("ZipCode"). I think I have used Dim I As long before so maybe that is cousiung an issue.. idk.. Please help!!! :) Maybe I am just missing something and am not noticing the smallest detail...


Code:
Private Sub ZipCode_Change()Dim I As Long, Lastrow As Long
Lastrow = Sheets("Zips").Range("A" & Rows.Count).End(xlUp).Row
For I = 2 To Lastrow


If Sheets("Zips").Cells(I, "A").Value = ZipCode Or _
Sheets("Zips").Cells(I, "A").Value = Val("ZipCode") Then


Me.State = Sheets("Zips").Cells(I, "B").Value
Me.City = Sheets("Zips").Cells(I, "C").Value






End If


Next






End Sub
 
ah ok duh, you need Zipcode_Exit() not Change. Change is triggering after each character typed in, even before the user finishes putting it all in :)
Your code will work probably if you move it to Zipcode_Exit or mine or Alphafrog's
 
Upvote 0

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Tried it and still noting. I seriously don't know why it wont work. I have no clue why... I am getting frustrated when I know the coding works in another part of my userform
 
Upvote 0
Your code has gotten me close. I input the zipcode and I get the error message that 99201 is not a valid zipcode but it is, and not transferring the other data
 
Upvote 0
And I remaned the sheet zips, but in the properties it is called "Sheet6" I will try "Sheet6". There are also a few other sheets so is that causing an issue? I am at a loss
 
Upvote 0
The zipcode number starts in Column A2 state is B2 and City is C2

They end in row 42538

I'm suspecting a formatting issue. How is the zipcode column formatted? Text? General? Number?
At any rate, using Zipcode_AfterUpdate use the following modified version of my code


if iserror(application.match("*" & Zipcode & "*", sheets("Zips").range("A:A"),0))=false then
matched = application.match("*" & Zipcode & "*", sheets("Zips").range("A:A"),0)
Me.State = Sheets("Zips").Cells(matched, "B").Value
Me.City = Sheets("Zips").Cells(matched, "C").Value
else
msgbox Zipcode & " not found in Zips list.", vbcritical, "ALERT"
exit sub
endif
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,430
Messages
6,119,454
Members
448,898
Latest member
drewmorgan128

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