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
 
It's done by just entering the number in the textbox. Then it populates. I just thought it would be nice if you make a mistake that when you clear the textbox it will clear the other textboxes
the red text I added should do the trick. Will clear before search result.
 
Upvote 0

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
I just added this bit.. It seems to work. I will try your way

Code:
 If ZipCode = "" Then  

Me.State = Clear
  Me.City = Clear
   End If[CODE]


Ok that didnt work lol I will try your way haha
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,056
Messages
6,122,907
Members
449,096
Latest member
dbomb1414

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