Hello,
below zou may find the code that I use. I advance I want to apologize in case I don't communicate clearly, since English is not my first language.
I marked the part of the code that troubles me with "+++ Problem here+++".
So what is my question/problem?:
The code should copy a certain range from a certain table. The problem is that depending on what month the user chooses a different worksheet will be selected, which means that I do not always want to copy data from the same table.
For example: The user chooses "September" (which will lead to a activation of a certain worksheet named "September"). In this case "Table2" is correct. But lets say the user chooses "October". In this case "Table3" would be correct, but since "Table2" is fixed in the code, using the macro will result in en error.
So my question:
Is it possible to choose the table in accordance with the selected month? Respectively is it posible to define variable for table?
A lot of thanks in advance!
Sub Trabajo()
Dim mes As String
Dim message As Integer
Workbooks.Open Excel Training\Test Macro\BAB Expenses Detail.xlsm"
Windows("DBBAB2017.xlsm").Activate
Sheets("DB2017").Select
mes = Cells(7, 31).Value
If mes = "Seleccionar Mes" Then
message = MsgBox("Select a month", vbOKOnly, "Warning")
If message = vbOK Then
Exit Sub
Else
End If
Else
Windows("BAB Expenses Detail.xlsm").Activate
On Error GoTo ErrorHandler
Sheets(mes).Activate
Range("Table2[COMPANIA]").Select +++ Problem here+++
Selection.Copy
Windows("DBBAB2017.xlsm").Activate
Sheets("DB2017").Range("Table1[[#Headers],[Co Number]]").Select
ActiveCell.End(xlDown).Offset(1, 0).Select
ActiveSheet.Paste
End If
Range("AE7").Select
Selection.FormulaLocal = "=""Seleccionar Mes"""
ErrorHandler:
message = MsgBox("Month is not active", vbOKOnly, "Warning")
If message = vbOK Then
Exit Sub
Else
End If
Bookmarks