简体   繁体   中英

VBA - Using RefEdit as Range

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

I tried this and it worked:

Dim s, w
s = RefEdit1.Value
Set w = Range(s)
MsgBox w.Cells(1, 1)

Try using this:

Range(UserForm.RefEdit.Value)

Remove the workbook . and worksheet .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM