Show Last Record in the Listbox when userform Loads.

S

Shazi

Hi,

when I load my userform, the following procedure is showing the
listbox first record. how I can view the last record in the ListBox
when userform loads.

I am using this code:

Option Explicit
Dim LastRow As Long

Private Sub UserForm_Initialize()

Sheets("DailyIssue").Select

'to hide Blank Rows in ListBox.
LastRow = Worksheets("DailyIssue").Cells(Rows.Count,
"A").End(xlUp).Row
ListBox1.RowSource = "A5:J" & LastRow

End Sub


Regards.

Syed Shahzad Zafar
 
B

Bob Phillips

See previous posting

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
R

Rick Rothstein \(MVP - VB\)

I think you want to do this at the end of your code...

ListBox1.ListIndex = ListBox1.ListCount - 1

Rick
 
R

Rick Rothstein \(MVP - VB\)

Why did you post your question twice... and within 4 minutes of each other
no less? Did you really think that after 4 minutes you had waited too long
for a response? I only ask because there was no need for me to post my
answer as you already had the same answer from someone else in your other
question; however, I hadn't read to the other posting to see that before
constructing an answer to the first post I saw when I came online. The
people answering questions here are volunteers... there is not always
someone available... in the future, please just post your question once and
then wait... this way you won't waste the volunteers' time constructing
answers to questions you already have an answer to elsewhere.

Rick
 
S

Shazi

Why did you post your question twice... and within 4 minutes of each other
no less? Did you really think that after 4 minutes you had waited too long
for a response? I only ask because there was no need for me to post my
answer as you already had the same answer from someone else in your other
question; however, I hadn't read to the other posting to see that before
constructing an answer to the first post I saw when I came online. The
people answering questions here are volunteers... there is not always
someone available... in the future, please just post your question once and
then wait... this way you won't waste the volunteers' time constructing
answers to questions you already have an answer to elsewhere.

Rick

message




- Show quoted text -

Dear Mr. Rick,

There was a problem with my Internet connection, it was stuck when I
tried to send my post, whenn I click on Send button, the blank screen
came out, and my pc was stuck, I closed the my browser from the Task
Manager.

It was not intentially, it was happen may be Internet connection
stopped or there was problem with my pc.

I am not sending any message twice, always I am waiting for my reply
at least 12 hours......... a day.

any way sorry for inconvenience.

Regards

Shahzad
 
S

Shazi

I think you want to do this at the end of your code...

ListBox1.ListIndex = ListBox1.ListCount - 1

Rick











- Show quoted text -

Mr. Rick,
Hi,

If I want to see the first record in the Listbox then what to do.
pls help me.

Shahzad
 
R

Rick Rothstein \(MVP - VB\)

<< Top-Posted Listing Repaired>>

Please use the same posting order as your responder; in the case of this
thread, I top-posted my reply, so you should have top-posted your reply to
me (this makes it easier for anyone looking at this thread in the archives
to follow the replies in order of their posting).

To answer your question, the ListIndex is a zero-based index into the list
(much like the index value of an array). Since you want the first item in
the ListBox, and since the ListIndex is a zero-based index, you would use
this....

ListBox1.ListIndex = 0

to select the first item in the list.

Rick
 
S

Shazi

<< Top-Posted Listing Repaired>>

Please use the same posting order as your responder; in the case of this
thread, I top-posted my reply, so you should have top-posted your reply to
me (this makes it easier for anyone looking at this thread in the archives
to follow the replies in order of their posting).

To answer your question, the ListIndex is a zero-based index into the list
(much like the index value of an array). Since you want the first item in
the ListBox, and since the ListIndex is a zero-based index, you would use
this....

ListBox1.ListIndex = 0

to select the first item in the list.

Rick







- Show quoted text -

Hi,

Thank you Mr. Rick, now its working properly.

Regards.

Shahzad
 
R

Rick Rothstein \(MVP - VB\)

You are welcome, but you bottom-posted your answer again.

Rick


<< Top-Posted Listing Repaired>>

Please use the same posting order as your responder; in the case of this
thread, I top-posted my reply, so you should have top-posted your reply to
me (this makes it easier for anyone looking at this thread in the archives
to follow the replies in order of their posting).

To answer your question, the ListIndex is a zero-based index into the list
(much like the index value of an array). Since you want the first item in
the ListBox, and since the ListIndex is a zero-based index, you would use
this....

ListBox1.ListIndex = 0

to select the first item in the list.

Rick







- Show quoted text -

Hi,

Thank you Mr. Rick, now its working properly.

Regards.

Shahzad
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top