Still new to VBA...
I'm trying to pull data from a worksheet (changes with selection) with the link written in cell C5 ("Instructions" worksheet). It was pulling correctly into columns on my active sheet ("Updates"), but now the code will results in
Compile error: End if without block if
Please help! Thank you
Ps: At the end, I still need to add code to save the updated worksheet as a CSV copy
Private Sub CommandButton1_Click()
Dim wb As Workbook
Dim rng As Range
Dim wsCurrent As Worksheet
Dim DefaultFile As String
Set wsCurrent = ActiveSheet
DefaultFile = ActiveWorkbook.Worksheets("Instructions").Range("C5")
If Dir(DefaultFile) = vbNullString Then
MsgBox DefaultFile & vbNewLine & "does not exist." & vbNewLine & "What Now?"
Else
With Application.FileDialog(msoFileDialogOpen)
.AllowMultiSelect = False
.InitialFileName = DefaultFile
.Show
If .SelectedItems.Count > 0 Then
Set wb = Workbooks.Open(.SelectedItems(1))
With wb.Sheets(1)
Set rng = .Range(.Range("B2"), .Range("B2").End(xlDown))
rng.Copy wsCurrent.Range("B4")
wb.Close False
With wb.Sheets(1)
Set rng = .Range(.Range("A2"), .Range("A2").End(xlDown))
rng.Copy wsCurrent.Range("C4")
wb.Close False
With wb.Sheets(1)
Set rng = .Range(.Range("F2"), .Range("F2").End(xlDown))
rng.Copy wsCurrent.Range("M4")
wb.Close False
End With
End If
End With
End If
End Sub
Aucun commentaire:
Enregistrer un commentaire