Confused! about Excel Fun with VBA Excel VBA USERFORMS #2 Sort Database By Employee Id

Robert Allan

New Member
Joined
Mar 30, 2020
Messages
19
Office Version
  1. 365
Platform
  1. Windows
Confused!

I’m trying to follow along with the Excel VBA USERFORMS #2 Sort Database By Employee Id. I seem to be susessful, except for one part. I have watch it many times, and just don’t understand ( and could not make out what he said) in this part:

If Cells(Rows.Count, 1).End(xlUp).Row = 1 Then

lr = 2

Else

ir =.Cells(Row.Count, 1).End(xlUp).Row

End If

I understand how to get to last row and what these lines mean, but first he types in “lrcode”, and says something that I can’t hear very well. The “ircode” paste the above lines into the sub-routine. Then vanishes. My question is, what is “lrccode” and how does it work.
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Just before he types in lrcode, he says he uses Type Pilot. It's a utility running in the background. The user creates a shortcut phrase or keyword (lrcode) and Type Pilot automatically replaces it with a longer phrase e.g. his last row code.
 
Upvote 0
Plus the code you provided has some errors:

VBA Code:
If Cells(Rows.Count, 1).End(xlUp).Row = 1 Then

        lr = 2

    Else

        ir =.Cells(Row.Count, 1).End(xlUp).Row

    End If

You must be using a With statement elsewhere or the .Cells on the 4th row would fail but you dont use it in the 1st row. That should also use .Cells(.Rows. Then your variable changes from lr to ir. They should both be lr no doubt. You also have Row.Count which should be Rows not Row. The statement should therefore be:

VBA Code:
If .Cells(.Rows.Count, 1).End(xlUp).Row = 1 Then

        lr = 2

    Else

        lr =.Cells(.Rows.Count, 1).End(xlUp).Row

    End If

You could make this one row with:

VBA Code:
lr = Application.Max(2, .Cells(.Rows.Count, 1).End(xlUp).Row)

but you must be wrapping all these with a WITH statement pointing to a worksheet. eg

VBA Code:
With Sheets("Sheet1")
'your code
End With
 
Upvote 0
Just before he types in lrcode, he says he uses Type Pilot. It's a utility running in the background. The user creates a shortcut phrase or keyword (lrcode) and Type Pilot automatically replaces it with a longer phrase e.g. his last row code.
No longer Confused!

Thanks so much, I kind of thought that that is what he was saying. But when I tried to find something on Type Pilot, I couldn’t. I was looking for something inside of Excel. I had no idea that it did not have anything to do with Excel. Now that I know, and you straighten me out, I got a copy of it and love it. I will probably be using all the time now. I thought maybe it had something to do with my bug, but I was wrong. I’m not going to share my problem was you(I want to work it out myself.), because working out bugs is half the fun of programming. But you was a big help, and I thank you again.
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,272
Members
449,075
Latest member
staticfluids

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