Hi, I just learned how to populate combo box with the sheet names of the selected workbook. Please forgive me if I ask stupid questions, as I'm new in this. Further to my project, When a file is being selected, it's sheet's names also appears in combo box. Now, what I need is that when any of these sheet is selected, that entire sheet should be copied to the NEW sheet of active workbook, renaming it ""Sheet name"Sheet". For example, if a sheet named "Input" is copied to active workbook, then a new sheet is added automatically, renaming that sheet to "InputSheet". I tried doing this by my own, but unable to think any further:
Now I don't know whether I should add the COPY CODE before adding a new sheet or after. Also, I don't know where to write the code for SELECTED sheet from combo box.(CopySheet_Click or Browse_Click). Browse_Click and CopySheet_Click are two buttons in user form for Browsing excel file from the computer and Copying the selected sheet to active workbook respectively.
Code:
Private Sub BrowseButton_Click() Dim fName As String
Dim wb As Workbook
Dim ws As Worksheet
fName = Application.GetOpenFilename("Excel Files(*.xlsm),*.xlsm", , "Please select one **** excel file", , False)
If fName <> "" Then
TextBox1.Value = fName
Set wb = Workbooks.Open(fName)
For Each ws In wb.Worksheets
ComboBox1.AddItem ws.Name
Next
wb.Close True
UserForm2.ComboBox1.Text = UserForm2.ComboBox1.List(0)
Set wb = Nothing
Else
MsgBox "No file is selected.", vbExclamation, "Sorry!"
End If
End Sub
Private Sub CopySheet_Click()
With ThisWorkbook
.Sheets.Add(, .Sheets(.Sheets.Count)).Name = ws.Name & "Sheet"
End With
End Sub
Now I don't know whether I should add the COPY CODE before adding a new sheet or after. Also, I don't know where to write the code for SELECTED sheet from combo box.(CopySheet_Click or Browse_Click). Browse_Click and CopySheet_Click are two buttons in user form for Browsing excel file from the computer and Copying the selected sheet to active workbook respectively.