I've got this program that I want to have the user select a range in one workbook, close that workbook, and then paste that selection in the second workbook. This is VBA code for an excel document. Here is the selection code...
Function SelectARange(sPrompt As String, sCaption As String, oReturnedRange As Range) As Boolean
Dim frmSelectCells As ufSelectCells
Set frmSelectCells = New ufSelectCells
With frmSelectCells
.PromptText = sPrompt
.CaptionText = sCaption
If TypeName(Selection) = "Range" Then
.StartAddress = Selection.Address(external:=True)
End If
.Initialise
.Show
If .OK Then
Set oReturnedRange = .ReturnedRange
If oReturnedRange Is Nothing Then
SelectARange = False
Else
SelectARange = True
End If
Else
SelectARange = False
End If
End With
Unload frmSelectCells
Set frmSelectCells = Nothing
End Function
And here is what I thought would work...
goBack = 1
Do While (goBack <> 0)
Dim percentCopy As Range
If SelectARange("Select the month's cost / budget range of both '% year' AND '% actual'.", "Range Select", oRangeSelected) = True Then
addingRows = (oRangeSelected.count / 2)
Set precentCopy = oRangeSelected
goBack = 0
Else
If (MsgBox("You have pressed cancel, go back?", vbYesNo, "Automation Tip") = vbNo) Then
goBack = 0
Else
goBack = 1
End If
End If
Loop
otherBook.Close
Dim destRange As Range
Set destRange = Range(Cells(ActiveCell.Row, ActiveCell.Column), Cells(ActiveCell.Row + addingRows - 1, ActiveCell.Column + 1))
destRange.Select
percentCopy.Copy destRange
Does anyone have anything that can help?