Select Which Sheet to Import Data From

cbzdmh

Board Regular
Joined
Jul 16, 2007
Messages
58
Hi I'm trying to import data from a specific sheet in a workbook.

So far I have, it checks that the destination sheet is valid, once that has been done it gets a list of all the sheets from the source workbook and populates a list box in a user form.

I then can't select the sheet to copy the data off.

Code:
Sub Import_Flash()

'Imports a selected Page from a selected workbook
Dim SourceFileName As String
Dim TargetBook As String
Dim sheetexists As Boolean
Dim FlashImportSheet As String

'Checks for target sheet using Checkforsh, if it doesn't exist it creates it
   shtexists = CheckForSheet("Imported Flash")
    If Not shtexists Then
        Sheets.Add
        ActiveSheet.Name = "Imported Flash"
    Else
        Sheets("Imported Flash").Select
        Cells.Select
        Selection.ClearContents
    End If
    
TargetBook = ActiveWorkbook.Name
SourceFileName = Application.GetOpenFilename

If SourceFileName = "False" Then
        Exit Sub
ElseIf SourceFileName <> "" Then
        Workbooks.Open Filename:=SourceFileName
            
            With ActiveWorkbook
                For Each Sh In ActiveWorkbook.Worksheets
                    If Sh.Visible = True Then
                    FlashImport.FlashList.AddItem Sh.Name
                    End If
                Next Sh

'launches user form called FlashImport which lists all sheets in workbook
                FlashImport.Show

'
' THIS IS WHERE IT GOES WRONG, I CAN'T GET THE VARIABLE BACK FROM THE USERFORM 
'
                Sheets(FlashImportSheet).Select
                Cells.Select
                Selection.Copy
            End With
                
            Windows(TargetBook).Activate
            Range("A1").Select
            Selection.PasteSpecial Paste:=xlPasteValues
            'Cells.Select
            'Selection.RowHeight = 14
            'Cells.EntireColumn.AutoFit
           
End If
    
End Sub


The userform code
Code:
Sub FlashList_Change()
FlashImportSheet = FlashList.Value
FlashImport.Hide
End Sub
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
I think I've just got to get the variable from the userform code back to the module, but i can't remember how.
 
Upvote 0
If you use a command button to submit your data then once you submit the data run the remaining code to your requirements.
 
Upvote 0

Forum statistics

Threads
1,214,642
Messages
6,120,698
Members
448,979
Latest member
DET4492

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top