View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Vacuum Sealed Vacuum Sealed is offline
external usenet poster
 
Posts: 259
Default Compile Error:Variable not defined

Hi Seth

You have to Dim ( which is kinda like Declaring ) what each string,
range, variant is.

1st Example would read something like:

Sub GuessName()

Dim ans As Integer

ans = MsgBox("Is your name " & Application.UserName & "?", vbYesNo)
If ans = vbNo Then
MsgBox ("Oh, never mind.")
Else
MsgBox ("I must be clairvoyant!")
End If

End Sub


2nd example will replace any formulas in cells within the range you
specify with their actual values.

Again, we Dim what it is we are pointing to eg, the objects and ranges.

Sub ConvertFormula_2()

Dim mySht As Worksheet
Dim myFormulaRange As Range, fCell As Range
Dim answer As Integer

Set mySht = Sheets("Sheet1") 'çhange name to your sheet name.
Set myFormulaRange = mySht.Range("A1:A2") 'çhange range to suit.

answer = MsgBox("Convert formulas to values?", vbYesNo)
If answer < vbYes Then Exit Sub

For Each fCell In myFormulaRange
If fCell < "" Then

With fCell
.Value = fCell
End With
End If
Next

End Sub

Now, my terminology I use may not be 100% accurate, but hopefully it
will point you in the right direction.

One of the many Guru's will no doubt correct any ambiguous terminology
mistakes I have made....

HTH
Mick.