JFro777
JFro777

Reputation: 71

VBA Dialog box to select range in different workbook hanging up

I used the code that was responded with in the link I have attached below and I am having some problems can you please help me?

VBA Dialog box to select range in different workbook

When I click on the refedit box to be able to select the range I want to use it is hanging up and I'm getting a sound when I click saying that there is another window open somewhere with higher priority but i cannot find it.

Basically, what I'm trying to do is copy the specified columns from one workbook and paste them into a sheet on my original workbook. I know that my "copyButton_Click()" coding isn't right also but I cannot get that far into the debugging to fix it. Here is what I have:

MODULE 1:

  Sub extractData()
    Dim FName As Variant
    Dim wb As Workbook
    Dim destSheet As String
    '
    Application.ScreenUpdating = False
    destSheet = "NewData"
    '
    'Selects and clears data
    Sheets(destSheet).Select
        Range("A2:I12000").Select
        Selection.delete Shift:=xlUp
        Range("A2").Select
    '
    'Prompts user to select updated ILP file to copy data from:
    FName = Application.GetOpenFilename(filefilter:="Excel Files (*.xls;*.xlsx;*.xlsm), *.xls;*.xlsx;*.xlsm")
        If FName <> False Then
        Set wb = Workbooks.Open(FName)
    '
    ExtractCompareUserForm.Show vbModeless
    '
        End If

    Application.ScreenUpdating = True

    End Sub

USERFORM CODE:

  Private Sub UserForm_Initialize()
        Dim wb As Workbook

    '~~> Get the name of all the workbooks in the combobox
        For Each wb In Application.Workbooks
            ComboBox1.AddItem wb.Name
        Next

        ComboBox1 = ActiveWorkbook.Name
    End Sub

    '~~> This lets you toggle between all open workbooks
    Private Sub Combobox1_Change()
        If ComboBox1 <> "" Then Application.Workbooks(ComboBox1.Text).Activate

        Label1.Caption = "": RefEdit1 = ""
    End Sub

    '~~> This lets you choose the relevant range
    Private Sub RefEdit1_Change()
        Label1.Caption = ""

        If RefEdit1.Value <> "" Then _
        Label1.Caption = "[" & ComboBox1 & "]" & RefEdit1
    End Sub

    Private Sub copyButton_Click()
    Dim addr As String
    '
    addr = RefEdit1.Value
    '
    'Copy Data:
        UserForm1.addr = Selection.Address
        addr.Copy

    End Sub

    Private Sub PasteButton_Click()
    Dim destSheet As String
    '
    Workbooks(2).Close SaveChanges:=False
    '
    '       Now, paste to working workbook:
            Sheets("NewData").Activate
            Range("B2").Select
            ActiveSheet.Paste
            Application.CutCopyMode = False
        Unload Me
        '
    Call CopyData

    End Sub

Here is where it's hanging up and doesn't let me click on anything.

Upvotes: 1

Views: 414

Answers (1)

R3uK
R3uK

Reputation: 14547

You have deactivate the screen updating, you need to reactivate it before showing your UserForm, at the end of Sub extractData() :

You have :

    ExtractCompareUserForm.Show vbModeless
End If
Application.ScreenUpdating = True
End Sub

Switch to :

    Application.ScreenUpdating = True
    ExtractCompareUserForm.Show vbModal
End If
End Sub

Upvotes: 1

Related Questions