ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Code for activating shift key (https://www.excelbanter.com/excel-programming/390832-code-activating-shift-key.html)

BCLivell

Code for activating shift key
 
I need help with finding code that will virtually hold down the shift key. I
code that will select one cell and then i have it finding a second cell but I
it to "hold the shift key" inbetween so it copies all of the cels inbetween.
See below for the code i have so far. thank you!

Private Sub CommandButton1_Click()
Dim rng As Range
Dim cell As Range

Set rng = Range("B1:B1000")

startrow = Columns(2).Find("example 1").Select
ActiveCell.Copy

****Hold shift key****

startrow = Columns(2).Find("example 2").Select
ActiveCell.Copy

***End holding shift key****


End Sub

JE McGimpsey

Code for activating shift key
 
How about:

Private Sub CommandButton1_Click()
Dim r1 As Range
Dim r2 As Range

With Range("B:B")
Set r1 = .Find("example 1")
If Not r1 Is Nothing Then
Set r2 = .Find("example 2")
If Not r2 Is Nothing Then
Range(r1, r2).Copy _
Destination:=Sheets("Sheet2").Range("A1")
End If
End If
End With
End Sub


In article ,
BCLivell wrote:

I need help with finding code that will virtually hold down the shift key. I
code that will select one cell and then i have it finding a second cell but I
it to "hold the shift key" inbetween so it copies all of the cels inbetween.
See below for the code i have so far. thank you!

Private Sub CommandButton1_Click()
Dim rng As Range
Dim cell As Range

Set rng = Range("B1:B1000")

startrow = Columns(2).Find("example 1").Select
ActiveCell.Copy

****Hold shift key****

startrow = Columns(2).Find("example 2").Select
ActiveCell.Copy

***End holding shift key****


End Sub



All times are GMT +1. The time now is 12:17 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com