+ Reply to Thread
Results 1 to 1 of 1

Posible to define variable for table?

  1. #1
    Registered User
    Join Date
    01-06-2018
    Location
    Monterrey
    MS-Off Ver
    2013
    Posts
    1

    Posible to define variable for table?

    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
    Last edited by sombreroeistee; 01-06-2018 at 02:43 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Problem with creating a reference table
    By JimmyOS in forum Excel General
    Replies: 4
    Last Post: 02-27-2016, 07:28 AM
  2. Replies: 1
    Last Post: 08-14-2015, 02:49 AM
  3. [SOLVED] Problem with linking offset function and reference table
    By mjo1983 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 02-13-2015, 09:46 PM
  4. Replies: 5
    Last Post: 06-17-2014, 10:16 AM
  5. Replies: 2
    Last Post: 05-05-2014, 04:37 AM
  6. Problem in pivot-table reference
    By Aashik in forum Excel Charting & Pivots
    Replies: 3
    Last Post: 06-23-2013, 01:57 AM
  7. Replies: 3
    Last Post: 05-13-2009, 11:51 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1