View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Greg Wilson Greg Wilson is offline
external usenet poster
 
Posts: 747
Default please help! Replacing blank cells from a userform textbox

Point 1:
This is what I was implying in my second post. The remedy was to expand the
used range, say during setup, of the db worksheets. I'm sure you can find a
reason to put text on the worksheet at or beyond the farthest column that wil
be populated by the macro (I believe column F for Sheet1). Experimentally at
least, insert an "x" or something. This will expand the used range in width.
If I have it right, data entry by the macro of project numbers will expand
the used range height automatically. If that's not correct, do similar for a
row.

The used range is not just a concept. Excel for efficiency's sake limits
worksheet memory in some way only to those cells within the rectanglular
range defined by the farthest column and farthest row that have been changed
by data entry or formatting. My take is that cells outside of the used range
have not been initialize in some sense and do not contain an empty string
("") or any data type (or perhaps vbNullString?).

My interpretation is that the Replace function (both mine and your versions)
looks for text in the referenced cells, even if an empty string (""), and
replaces it with the given value. However, for the reason described, the
function fails when it references beyond the used range.

Point 2:
My code offering was only a simplified replica of yours based on
interpretation. It also contains error handling ("If Not c Is Nothing Then")
in case a job number is not found. By itself, it won't fix the problem unless
failure to find a job number is the actual cause. It still should be helpful.

Greg