using the immediate window to print out a variable value

J

Janis

JE McGimpsey gave me this macro. I would like to test the value in the
variable to make sure I have it stored before I delete the row. I'm trying
to figure out how to use the "immediate window" debugger. How do you print
out the value of the varible I just stuffed? I get an invalid qualifier on
the debugger line.
thanks,

Private Sub deleteDateRow1()
'
' deleteDateRow1 Macro
Dim FrReptDate As Date


With Range("A1")
FrReptDate = .Value
.EntireRow.Delete Shift:=xlUp
End With
Debug.Print FrReptDate.Text

End Sub
 
J

JE McGimpsey

Janis said:
JE McGimpsey gave me this macro. I would like to test the value in the
variable to make sure I have it stored before I delete the row. I'm trying
to figure out how to use the "immediate window" debugger. How do you print
out the value of the varible I just stuffed? I get an invalid qualifier on
the debugger line.
thanks,

Private Sub deleteDateRow1()
'
' deleteDateRow1 Macro
Dim FrReptDate As Date


With Range("A1")
FrReptDate = .Value
.EntireRow.Delete Shift:=xlUp
End With
Debug.Print FrReptDate.Text

End Sub

You've declared FrReptDate as a Date variable. Date variables, like most
variables, can only have a value (or Nothing) assigned to it, so you
simply use

Debug.Print FrReptDate

OTOH, .Text is a property of an object, such as a Range object, a
ComboBox object, a Characters object, etc. Since FrReptDate is not an
object, it's an "invalid qualifier" for .Text.

If instead, you'd declared something like:

Dim FrReptDateCell As Range
Set FrReptDateCell = Range("A1")

(note that you need to use "Set" to assign objects to object variables),
you could then use

Debug.Print FrReptDateCell.Text

to display the Text in the object associated with the FrReptDateCell
object variable (in this case, cell A1 of the active sheet).
 
J

Janis

JE:
I changed it to add the to report date variable and now I can't figure out
how to select the cell in the range.
thanks,


Private Sub deleteDateRow1()

' deleteDateRow1 Macro
Dim FrReptDate As Date
Dim ToReptDate As Date
Dim rng As Range
Set rng = Range("A1", "B1")
With rng
FrReptDate = Cells.A1
ToReptDate = Cells.B1
.EntireRow.Delete Shift:=xlUp

Debug.Print FrReptDate.Text & ToReptDate.Text
End With
End Sub
 
J

Janis

JE I tried it another way, following what you said but it doesn't like the
set statements
it says type mismatch
thnks,
Private Sub deleteDateRow1()
'
' deleteDateRow1 Macro
Dim FrReptDateCell As Range
Dim ToReptDateCell As Range


Set FrReptDateCell = ("A1")
Set ToReptDateCell = ("B1")

.EntireRow.Delete Shift:=xlUp

Debug.Print FrReptDate.Text & ToReptDate.Text
End With
End Sub
 
J

Janis

JE:
I got past setting the variable. Now it only deletes the first cell not the
first row.




Private Sub deleteDateRow1()
'
' deleteDateRow1 Macro
Dim FrReptDateCell As Range
Dim ToReptDateCell As Range


Set FrReptDateCell = Range("A1")
Set ToReptDateCell = Range("B1")

Range("A1").Select
Selection.Delete Shift:=xlUp

Debug.Print FrReptDateCell.Text & ToReptDateCell.Text

End Sub
thanks,
 
J

Janis

JE
This is try 3. This time it compiled but it deleted every row in my sheet?

Private Sub deleteDateRow1()
'
' deleteDateRow1 Macro
Dim FrReptDateCell As Range
Dim ToReptDateCell As Range




Set FrReptDateCell = Range("A1")
Set ToReptDateCell = Range("B1")

Range("A1").Row.Select
Selection.Delete Shift:=xlUp

Debug.Print FrReptDateCell.Text & ToReptDateCell.Text

End Sub
Janis
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top