[HOW] Format a variable?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Guest
Hey, I`ve got a little problem, it`s not that hard but I want to put my finger on it.

This is a piece of my macro:

Sub workbook_beforeclose(cancel As Boolean)
Dim lc As Long, scan As Boolean
'scanning for empty cells in row 96
scan = True
For lc = 1 To 21
If Len(Cells(96, lc)) = 0 Then
scan = False
Exit For
End If
Next
If scan = False Then
MsgBox "value in colomn " & CStr(lc) & " is missing. Sheet will not be closed" _
, vbCritical, "uncomplete!"
cancel = True
Exit Sub
End If
If scan = True Then
scanpast
Else
End If
End Sub

As you can see, what is does is scan for empty cells in row 96. If it all cells a filled it will continue to the next routine (which is not shown here) if one of the cell in 96 is empty, a message will appear telling you which cell exactly is empty.


Now: what I want to do is format the variable LC so that the message not be:


"value in colomn 3 is missing. Sheet will not be closed"

but:

"value for Temperature is missing. Sheet will not be closed"

Can anyone help me with this!?

Thanks a lot!
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Do you keep the column title in the first row of each column ? If so, then, instead of using just LC, use Cells(1,LC), that should give you the Column Name.

Another, thing, I HATE loops ! those are just too slow ! try with this formula instead:

scan = Not Evaluate("OR(LEN(A96:U96)=0)")

In one line you know if any cell in A96:U96 is empty. Now, to know which column is empty, try this:

LC = Evaluate("MATCH("""",A96:U96,0)")

Or in VBA language:
LC = Application.Match("",Range("A96:U96"),0)

How's that ?
 
Upvote 0
Just thought for a better formula for LC

LC = Evaluate("MATCH(0,LEN(A96:U96),0)")

This can't be obtanied directly in VBA because it's an array formula, which would force you to put the result in a cell first, and then, read the content of that cell.
 
Upvote 0

Forum statistics

Threads
1,223,311
Messages
6,171,363
Members
452,397
Latest member
ddneptune

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