selection problem.

itwillblowyourmind

New Member
Joined
Jan 25, 2005
Messages
1
Hi,

Can anyone help me please.

I have a sheet that collects data for the day. column A just has dates in it for the whole year. this sheets works fine, no problems.

I have another workbook to pull specific data into.
In this workbook I have a userform with 2 textboxes. The first textbox is where the user selects the date "From" and the second is where the user selects the date "To".

What I can't seem to get working is the code to.....

Find the first date "From" then find the second date "To" and select everything inbetween and copy it.

any ideas.
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.

Bruno

Active Member
Joined
Feb 17, 2002
Messages
491
Hi itwillblowyourmind,
Welcome to the board.

Try this
Code:
Private Sub CommandButton1_Click()
Dim strStartDate As Date
Dim strEndDate As Date
Dim rngSearch As Range
Dim rngStartSelection As Range
Dim rngEndSelection As Range

    Set rngSearch = Sheets("Sheet1").Range("A1:A400")
    
    strStartDate = Me.TextBox1.Value
    Set rngStartSelection = rngSearch.Find(What:=strStartDate)
    If rngStartSelection Is Nothing Then
        MsgBox "Start date error"
        Exit Sub
    End If
    
    strEndDate = Me.TextBox2.Value
    Set rngEndSelection = rngSearch.Find(What:=strEndDate)
    If rngEndSelection Is Nothing Then
        MsgBox "End date error"
            Exit Sub
    End If

    Range(rngStartSelection, rngEndSelection).Select
End Sub
 

Forum statistics

Threads
1,147,510
Messages
5,741,582
Members
423,669
Latest member
necat02

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
Top