0

I have a code snippet which tells me in which row a specific value is

With Tabelle1
Set pzrow = .Cells.Find(What:=pznr, LookIn:=xlValues, searchorder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, searchformat:=False) ' sucht die Nummer der Zeile raus
End With

The value can differ between 1 and 29000. Just for cosmetic reasons I want to display the row in a Label caption:

pzrow1.Caption = "Eintrag Nr. " & pzrow.Row

and this should show "Eintrag Nr. 00001" for example, not "Eintrag Nr. 1"

Some Ideas?

braX
  • 11,506
  • 5
  • 20
  • 33
Leon S
  • 103
  • 1
  • 7

1 Answers1

3

You can use Format$() to specify how many digits:

pzrow1.Caption = "Eintrag Nr. " & Format$(pzrow.Row, "00000")
braX
  • 11,506
  • 5
  • 20
  • 33
  • I've seen lately the `Format$` what is the `$` for braX? – Damian Dec 20 '19 at 11:03
  • It's optional... It used to be required, but not anymore. I just use it out of old habit. – braX Dec 20 '19 at 11:04
  • 1
    @Damian: You will find an explanation [Here](https://stackoverflow.com/questions/10890892/use-of-symbol-hash-in-vba-macro) – Siddharth Rout Dec 20 '19 at 11:22
  • @SiddharthRout - I knew it meant `String` but since there is no math being done with it, why would it matter "back in the day"? (per your link) – braX Dec 20 '19 at 11:29
  • @braX: Yes I am sure you knew. The comment was for Damian :) If I am not wrong, these are nothing but just shortcuts. Not sure about the "required part" though – Siddharth Rout Dec 20 '19 at 11:57
  • 1
    @SiddharthRout - I found this out of curiosity - Format$ is to be used specifically on a string variable. Format is to be used on any other usable data type. Both return strings. Format$ will always prove that little bit faster as it doesn't have to convert a different data type to a string. – braX Dec 21 '19 at 10:56