Share via

One question about using Macro

Anonymous
2019-05-13T05:32:12+00:00

I record macro, the code as below displayed. The purpose of this Macro is:

Step 1: click commandbar "Refresh All" as below red marked.

Step 2: Enter the word "Description" in Range B1. And use Data-Text to Columns to change date format.

Now the problem is: When run the macro, it fail to run the step 1, and directly skip to run step 2. Could you please give instruction how to revise the code to make step 1 done ? Thanks!

Here is the code for this macro:

Sub DescriptionDate()

'

' DescriptionDate Macro

' Refresh data, add Description, change date format, refresh Pivot, Save

'

' Keyboard Shortcut: Ctrl+z

'

    Selection.UnMerge

    ActiveWorkbook.Names.Add Name:="SAPCrosstab1", RefersToR1C1:= _

        "=BOBJ!R1C1:R5102C31"

    Selection.UnMerge

    ActiveSheet.Range("B1") = "Description"

    Columns("D:D").Select

    Selection.TextToColumns Destination:=Range("D1"), DataType:=xlDelimited, _

        TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _

        Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _

        :=Array(1, 3), TrailingMinusNumbers:=True

    Columns("E:E").Select

    Selection.TextToColumns Destination:=Range("E1"), DataType:=xlDelimited, _

        TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _

        Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _

        :=Array(1, 3), TrailingMinusNumbers:=True

    Columns("F:F").Select

    Selection.TextToColumns Destination:=Range("F1"), DataType:=xlDelimited, _

        TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _

        Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _

        :=Array(1, 3), TrailingMinusNumbers:=True

    Columns("G:G").Select

    Selection.TextToColumns Destination:=Range("G1"), DataType:=xlDelimited, _

        TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _

        Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _

        :=Array(1, 3), TrailingMinusNumbers:=True

    Columns("H:H").Select

    Selection.TextToColumns Destination:=Range("H1"), DataType:=xlDelimited, _

        TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _

        Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _

        :=Array(1, 3), TrailingMinusNumbers:=True

    Columns("I:I").Select

    Selection.TextToColumns Destination:=Range("I1"), DataType:=xlDelimited, _

        TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _

        Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _

        :=Array(1, 3), TrailingMinusNumbers:=True

    Columns("J:J").Select

    Selection.TextToColumns Destination:=Range("J1"), DataType:=xlDelimited, _

        TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _

        Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _

        :=Array(1, 3), TrailingMinusNumbers:=True

    Columns("K:K").Select

    Selection.TextToColumns Destination:=Range("K1"), DataType:=xlDelimited, _

        TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _

        Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _

        :=Array(1, 3), TrailingMinusNumbers:=True

    Columns("L:L").Select

    Selection.TextToColumns Destination:=Range("L1"), DataType:=xlDelimited, _

        TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _

        Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _

        :=Array(1, 3), TrailingMinusNumbers:=True

    Columns("M:M").Select

    Selection.TextToColumns Destination:=Range("M1"), DataType:=xlDelimited, _

        TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _

        Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _

        :=Array(1, 3), TrailingMinusNumbers:=True

    ActiveWorkbook.Save

    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

4 answers

Sort by: Most helpful
  1. Anonymous
    2019-05-14T01:12:16+00:00

    The add-in I installed is called "Analysis" for Excel.

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2019-05-13T12:51:48+00:00

    How did you get 'Anlaysis' tab on your ribbon? Which add-in are you using?

    If I can get it to show up on my ribbon and get your file then I can try to find the code behind the 'Refresh All' button.

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2019-05-13T07:26:08+00:00

    Yeah, I understand what you said, agree with you that the code from macro is incorrect.

    And I also have no idea how to find the equivalent VBA code to make step1 happen.

    Already tried your suggestion "Try to record a new macro and do only the first step. See what you get", but cannot be workable. 🤣😂😭

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2019-05-13T05:58:18+00:00

    Not all actions from the user interface get recorded in a macro. You will have to find the equivalent VBA code for the action you want and add to the macro. I do not have the 'Analysis' tab on my setup of Excel so unable to help you there.

    Something like

        ActiveWorkbook.RefreshAll

    Try to record a new macro and do only the first step. See what you get... it may be something similar to

        Selection.UnMerge

        ActiveWorkbook.Names.Add Name:="SAPCrosstab1", RefersToR1C1:= _

            "=BOBJ!R1C1:R5102C31"

        Selection.UnMerge

    Was this answer helpful?

    0 comments No comments