VBA InputBox Issue

Anonymous
2021-03-05T18:47:39+00:00

I have a simple macro. To copy values from one workbook to another in this case ML to MCR based on the user input number.

Number format can be e.g M5888-9087, M1990A 600111512, 453564034421 822349224.

Macro works with numbers like M5888-9087 but if I enter M1990A 600111512 or 453564034421 822349224 it copies all the rows instead of filtering M1990A 600111512 or 453564034421 822349224 and copying those selected rows.

Space in between is the culprit. How to overcome this?

Does changing the filter helps? I see other filters in object library.

Sub MCR()

Dim myInp As Variant

myInp = VBA.Interaction.InputBox(Prompt:="Enter the number", Title:="MCR Macro")

Windows("ML.xlsx").Activate

Worksheets("Full-View").Select

Worksheets("Full-View").ListObjects("Table1").Range.AutoFilter Field:=1, Criteria1:=myInp

Range("Table1[[#Headers],[Serial]]").Select

ActiveCell.Offset(1, 7).Range("Table1[[#Headers],[Serial]]").Select

Range(Selection, Selection.End(xlDown)).Select

Selection.Copy

Windows("MCR Macro.xlsm").Activate

Range("A4").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

:=False, Transpose:=False

End Sub

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

99 answers

Sort by: Newest
  1. Anonymous
    2021-04-12T13:31:29+00:00

    No. The template has no change in the order in both the Output and Categories. I follow the same order.

    In the categories sheet irrespective of the heading names it populates the categories sheet based on the names defined in the code that is good. Those names are found in the ws_Source_2 workbook.

    Issue is with wsSource_2 column order. In wsSource_2 workbook when I create the data set every week with updated data. The original source workbook has 50+ columns. I transform it through power query. I select the required columns and ignore the rest. I do joins to do lookup the Sub Name and Catergories from another workbook and Column W data from CSV is also lookup'd into the wsSource_2 workbook. 

    When I do this exercise every week the column order can get changed slight or more in wsSource_2. 

    Since you have the wsSource_2 workbook with you I will just mention the column names here. 

    If I change the order of the below columns could you check from your side does it still populate the Categories worksheet? Especially Sub Name, CQP, Category, columns try to move them to different place within A to W.

    Unique number

    Descr

    Half Number

    VC

    Name

    SUB 1

    SUB 2

    SUB 3

    SUB 4

    SUB 5

    SUB 6

    SUB 7

    SUB 8

    Evidence details

    Sub Findings

    S characteristics

    (if applicable)

    Sub Name

    CQP

    Category

    Code

    The below heading "S characteristics (if applicable)" has line break in the heading. But I did not face any issue when the code has the heading name as "S characteristics" It still recognizes the column. 

    S characteristics line break

    (if applicable)

    The above are the column headings (20 columns) for both Output sheet and Categories. The sample data set has 23, extra 3 columns will have data for Coversheet B13, B14, B15 cells. The data is not available for them right now.

    Was this answer helpful?

    0 comments No comments
  2. OssieMac 48,006 Reputation points Volunteer Moderator
    2021-04-12T11:06:42+00:00

    Have you also changed any column positions in the output workbook?

    If you upload an example of the source data then I will have a look at it and try to align the source columns with the output columns. Don't need all rows of the source data; just enough rows to test.

    Please include a list of the columns in the source data against a list of the matching columns in the destination. Just create the column lists in a worksheet so that one row has the source column names and the row under has the destination columns to which the data goes. Leave out any source data columns that are not copied.

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2021-04-12T10:37:20+00:00

    After spending last few days creating the data set and troubleshooting errors. At last I found that the macro works well on sample data set.

    But with the actual data set it works only if the column order is retained as in the wsSource sample data set workbook. If not the categories worksheet is all N/A even though there is data in the wsSource workbook.  

    I though it looks for data based on the column header name but when the column order changes output sheet works well but not the categories sheet.

    Also if the Description has / in it (e.g Device/340/540 or UTP/FX switch) it runs into a error file path not found. I replaced all / with space to avoid the error. 

    I hope you will be here to support if I face some issue with the macro in future. Because the actual dataset is huge as I run the macro further. I might encounter some issue like above e.g going forward. 

    In category 3 can we wrap the text as it is extending beyond the cell boundary. Let me know at which line the change is required so that I will add that line of code to my already adopted workbook.

    Was this answer helpful?

    0 comments No comments
  4. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  5. Anonymous
    2021-04-09T15:45:48+00:00

    I will share the file with you shortly. Creating the data set for Scenario 2 is a task. I am on it right now. May be that should also be done by macro using Find, Offset and Like functions. But that would make the macro run for a long time. Need to think about it.

    Was this answer helpful?

    0 comments No comments