SendKeys "{DOWN}"

Jaye7

Well-known Member
Joined
Jul 7, 2010
Messages
1,066
Hi Everyone,

I was provided the following script to use arrow down rather than activecell.offset as I have a filtered list and want to select the next cell down that is visible.

Code:
SendKeys "{DOWN}"

My problem now is that if I try to access the cell using the script the address is the old cell address before the arrow down script has run.

I.e. I run the arrow down script and then textbox4.value = activecell.address, yet it is not the activecell it is the previous cell which I don't want it to be.
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
This seems to work. It appears the key input is abandoned in some cases so we need to process the message queue.
Code:
Sub Bar()
    SendKeys "{Down}"
    DoEvents
    MsgBox ActiveCell.Address
End Sub
This appears to work equivalently, without sendkeys - I would generally avoid sendkeys unless there is other option:
Code:
Sub Foo()
    ActiveCell.End(xlDown).Select
    If Not Len(ActiveCell.Value) = 0 Then
        MsgBox ActiveCell.Address
    Else
        '//End of filtered list has been reached
    End If
End Sub
 
Upvote 0
Xenou,

The first script works great and I agree, I would rather not use send keys, I tried your second example and it isn't going to the next visible cell it is going to the last visible cell, can you please help with this.
 
Upvote 0
Oh, right. Well, I have used a loop for this in some cases. Should work, especially if dataset is not many (tens of) thousands of rows would still be fast. Otherwise, not sure. Depends on what needs to be done. Guess there's always SendKeys {grin}.

Code:
Sub Foo()
    
    Dim r As Range
    Set r = ActiveCell
    Do
        Set r = r.Offset(1)
    Loop While r.EntireRow.Hidden = True
    
    r.Select
    If Len(r.Value) > 0 Then
        MsgBox r.Address
    Else
        '//End of List
    End If
    
End Sub
 
Upvote 0
I'm not enough of an expert to tweak the appearance of disabled controls but I do see a "Locked" property on a userform textbox. A locked textbox has a normal appearance. Set Tab Stop to false. Users can still mouse into it, though (but not do anything else), so it's not a perfect solution.

You could also use a label for the purpose of showing text, though it probably doesn't look exactly like a normal textbox either.,
 
Upvote 0
Thanks anyway Xenou, I don't want people to access the box at all until they hit the modify key on my form which then allows them to edit the textboxes, unfortunately to do this it seems that you have to use the enable=false script which fades out the font.
 
Upvote 0

Forum statistics

Threads
1,223,229
Messages
6,170,881
Members
452,364
Latest member
springate

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