Question

I have a VBA script which opens a UserForm so the user can select various cell addresses for copying information from one file to another. I am using RefEdit controls to designate the cell address, but I am receiving an object error when I try to use the Workbook.Range(UserForm.RefEdit.Value) function, because the RefEdit reference is in the format "'Sheet1'!X#:X#". I know that if the RefEdit were just a range of cells I could do Workbook.Worksheet.Range(UserForm.RefEdit.Value), but the VBA script is being used for transitioning multiple files with different sheet names (so I can't use a universal Workbook.Worksheet string). Is there any way to use the RefEdit reference with both sheet name and cell address as a range?

Here is my current code:

Sub ReviseFAA()
Dim FolderPath As String, FilePath As String
Dim SourceFAA As Workbook, RevisedFAA As Workbook

FolderPath = "A:\Copy of MWO File\"
FilePath = Dir(FolderPath & "*.xls")

Do While FilePath <> ""
    Workbooks.Open (FolderPath & "FAA Template.xlsx")
    Set RevisedFAA = Workbooks("FAA Template.xlsx")
    Workbooks.Open (FolderPath & FilePath)
    Set SourceFAA = Workbooks(FilePath)

    FAA_User.Show

    With SourceFAA
    RevisedFAA.Sheets("Repair Instruction").Range("U2:AD3") = .Range(FAA_User.ControlNumber.Value).Value
    End With

    FilePath = Dir
Loop
Was it helpful?

Solution

Try using this:

Range(UserForm.RefEdit.Value)

Remove the workbook. and worksheet.

OTHER TIPS

I tried this and it worked:

Dim s, w
s = RefEdit1.Value
Set w = Range(s)
MsgBox w.Cells(1, 1)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top