title: How do I keep all the leading zeros on a Hexadecimal Range in VBA?
body: <p>I am trying to expand a range  of Hexadecimal numbers. For example I have on column K ...  1880 and column L ...188A  my range is 1880-188A When I expand the Range, starting On column M I get 1880 1881 1882 1883 1884 1885 1886 etc etc.</p>
  
  <p>From one of the posting I copied and changed the VBA script to fit my case... and it works ... but found 2 issues. All my device range are 4 digit and I need to keep all leading zeros.<br>
  For example if my range is 0000 - 0005 .... it errors... will not work.<br>
  If my range is 0001 - 0005 then I get 1 2 3 4 5.... and I want to be 0001 0002 0003 0004 0005</p>
  
  <p>Any help will be much appreciated..
  Thanks, JCam
  Here is the script that I use it ... as long as there are no leading zeros on my range</p>
  
  <hr>
  
  <pre><code>Sub FillHexNumbers()
  Dim cellKValue As Long
  Dim cellLValue As Long
  Dim diffBetweenKAndL As Long
  Dim iCtr As Long
  
  cellKValue = CLng(Format("&amp;h" &amp; Cells(2, 11).Text, "###"))
  cellLValue = CLng(Format("&amp;h" &amp; Cells(2, 12).Text, "###"))
  
  diffBetweenKAndL = cellLValue - cellKValue
  
  For iCtr = 0 To diffBetweenKAndL
      Cells(2, 13 + iCtr).Value = Hex(cellKValue + iCtr)
  Next
  End Sub
  </code></pre>