randolphoralph
Board Regular
- Joined
- Dec 24, 2008
- Messages
- 126
Using a input box to Copy and Paste
I am needing a macro that will use a input box to ask for user to enter a date to look for in Column A1:A100 on Sheet1 and if the date is found copy part of the row...for example if date is found in A5 the macro would copy B5:F5 then activate Sheet2 and look in Column B1:B100 for the same date and paste information...for example if same date found in B2 then information would paste into C2:G2.
Sheet1
A_______ B_C_D_E_F
10/1/2009 1 1 1 1 1
10/2/2009 2 2 2 2 2
Sheet2 before running macro
A________B_C_D_E_F_G
10/3/2009
10/1/2009
10/4/2009
Sheet2 after running macro
A_B_________C_D_E_F_G
__10/3/2009
__10/1/2009 1 1 1 1 1 1
__10/4/2009
I have found the code below but was not sure how to alter it to make it work for my situation.
I am needing a macro that will use a input box to ask for user to enter a date to look for in Column A1:A100 on Sheet1 and if the date is found copy part of the row...for example if date is found in A5 the macro would copy B5:F5 then activate Sheet2 and look in Column B1:B100 for the same date and paste information...for example if same date found in B2 then information would paste into C2:G2.
Sheet1
A_______ B_C_D_E_F
10/1/2009 1 1 1 1 1
10/2/2009 2 2 2 2 2
Sheet2 before running macro
A________B_C_D_E_F_G
10/3/2009
10/1/2009
10/4/2009
Sheet2 after running macro
A_B_________C_D_E_F_G
__10/3/2009
__10/1/2009 1 1 1 1 1 1
__10/4/2009
I have found the code below but was not sure how to alter it to make it work for my situation.
Code:
Sub btnFind_Click()
Dim strLastRow As String
Dim rngC As Range
Dim strToFind As String, FirstAddress As String
Dim wSht As Worksheet
Dim rngtest As String
Application.ScreenUpdating = False
Set wSht = Worksheets("Sheet2")
strToFind = InputBox("Enter the date to find")
With ActiveSheet.Range("A1:A100")
Set rngC = .Find(what:=strToFind, LookAt:=xlPart)
If Not rngC Is Nothing Then
FirstAddress = rngC.Address
Do
strLastRow = Worksheets("Sheet2").Range("B" & Rows.Count).End(xlUp).Row + 1
rngC.EntireRow.Copy wSht.Cells(strLastRow, 1)
Set rngC = .FindNext(rngC)
Loop While Not rngC Is Nothing And rngC.Address <> FirstAddress
End If
End With
MsgBox ("Finished")
End Sub
Last edited: