vba: update textbox based on excel values

Xlacs

Board Regular
Joined
Mar 31, 2021
Messages
105
Office Version
  1. 2016
Platform
  1. Windows
Hi Everyone,

I'm kinda new to VBA, so I was wondering if someone can help me figure out this problem.
For some reason, rows in excel is not positioning in the righ textbox. I have provide a screen shot of the error.

As you can see. My Date textbox is showing column B.
It should be in the name textbox.

Hoping for someone to help me on this.

Below is my code.

Thank you in Advance. =)

VBA Code:
Private Sub SearchBt_Click()
On Error Resume Next
Set FindData = Sheet1.Range("A:A").Find(Me.txt1.Value, , xlValues, xlWhole)
If FindData Is Nothing Then
    MsgBox ("Data Not Found")
    Exit Sub
Else
    LastRow = FindData.Row
End If
    
For DataCol = 1 To 16
    Me("Txt" & DataCol) = Sheet1.Cells(LastRow, DataCol).Value
Next DataCol

Problem
 

Attachments

  • ss1.png
    ss1.png
    3.3 KB · Views: 17
  • ss2.png
    ss2.png
    4.3 KB · Views: 19

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Your text boxes don't line up with your columns. Your columns don't provide a "Date" entry.
My advise: don't rely on any particular order, but give your text boxes a name that fits its purpose.
I'm the first one to admit, you can't use a loop anymore, but you won't be faced with surprises like these.
 
Upvote 0
Your text boxes don't line up with your columns. Your columns don't provide a "Date" entry.
My advise: don't rely on any particular order, but give your text boxes a name that fits its purpose.
I'm the first one to admit, you can't use a loop anymore, but you won't be faced with surprises like these.
Hello.

my date text is auto populated by my current date.
Sorry to ask, but can you show me the idea?
 
Upvote 0
This part of your code relies on a certain order ...
VBA Code:
For DataCol = 1 To 16
    Me("Txt" & DataCol) = Sheet1.Cells(LastRow, DataCol).Value
Next DataCol
:

... but it doesn't line up with the column order according to your screenshots.
Imo this order should be:
Book1
ABCDE
1EmpIDDateNamePositionLine Manager
2112-febemp 1post 1Line 1
3213-febRajiv KumarNew DelhiNew Delhi
Sheet1
 
Upvote 0
This part of your code relies on a certain order ...
VBA Code:
For DataCol = 1 To 16
    Me("Txt" & DataCol) = Sheet1.Cells(LastRow, DataCol).Value
Next DataCol
:

... but it doesn't line up with the column order according to your screenshots.
Imo this order should be:
Book1
ABCDE
1EmpIDDateNamePositionLine Manager
2112-febemp 1post 1Line 1
3213-febRajiv KumarNew DelhiNew Delhi
Sheet1

Yes. I'm wondering how I move and match my name textbox to column c

Edited: I see your point. Wew Thanks for that!
 
Last edited:
Upvote 0
You are welcome and thanks for letting me know (y)
 
Upvote 0

Forum statistics

Threads
1,214,872
Messages
6,122,026
Members
449,061
Latest member
TheRealJoaquin

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