Hello-
I cobbled together this code to copy data from another opened workbook and paste it onto a different workbook exactly where I want it to. It works great but I am having a hard time figuring out how to repeat (maybe loop) it without simply pasting it 20 times and manually updating it.
I need the subroutine to loop and instead of using my dimensional variable "Hilton1" to use "Hilton2", and then use "Hilton3" and so on. Thanks for your time.
Sub AutoImportHilton()
Dim w As Workbook
Dim wkboriginal As Excel.Workbook
Dim Hilton1 As Range
Dim Hilton2 As Range
Dim Hilton3 As Range
Dim rng As Range
InputDate = InputBox("Enter OTB Import Date MM-DD-YY")
Set wkboriginal = ActiveWorkbook
Set Hilton1 = Sheets("AutoImport").Range("B8")
Set Hilton2 = Sheets("AutoImport").Range("B9")
Set Hilton3 = Sheets("AutoImport").Range("B10")
For Each w In Application.Workbooks
If (w.Name) Like "*" & Hilton1 & "*" Then
Exit For
End If
Next w
If Not w Is Nothing Then
w.Activate
Else
MsgBox "No " & Hilton1 & " workbook found!"
End If
Range("D7", Range("D6").End(xlDown)).Select
Selection.ClearFormats
Selection.NumberFormat = "0"
Selection.HorizontalAlignment = xlCenter
Selection.Copy
wkboriginal.Activate
Worksheets("Input" & Hilton1).Select
Set rng = Cells.Find(What:="otb " & InputDate, LookIn:=xlValues)
If Not rng Is Nothing Then
rng.Activate
Else
MsgBox ("Date already used or not a weekday date")
Exit Sub
End If
Selection.PasteSpecial
End Sub
Bookmarks