Log in

View Full Version : Get value of current able cell



YossiD
03-04-2013, 12:30 AM
Feeling very dumb again.

I want to write a macro in Word to perform this basic algorithm:

If value of current table cell = a given number then select row and apply a particular style.

I'm sure it's dead easy, but I can't figure out how to check the value of the currently selected cell.

I'm using word 2003.

TIA

macropod
03-04-2013, 05:07 AM
Try:
Sub Demo()
Dim Rng As Range
With Selection
If .Information(wdWithInTable) = True Then
Set Rng = .Cells(1).Range
Rng.End = Rng.End - 1
If Rng.Text = "1" Then
.Rows(1).Range.Style = "MyStyle"
End If
End If
End With
End Sub
where '1' is the test number an 'MyStyle' is the Style to apply.

YossiD
03-05-2013, 12:25 AM
Thanks Paul, that worked a treat.

I suppose it's time for me to do some VBA tutorials so my brain can get into the VBA way of doing things. Any suggestions?

macropod
03-05-2013, 12:53 AM
I've never studied any vba tutorials - almost everything I know comes from studying how others have used it and from my own endeavours to help people like you solve their problems. So I can't really recommend any. That said, like me, you could do worse than studying the code used to solve problems on boards like this one.

Something I also encounter fairly often is people assuming a vba solution is required for a problem when the real issue is they don't know how to use the application's tools in the first place.