VBA - replace Recorded parts

Minkowski

Board Regular
Joined
Sep 16, 2009
Messages
157
hello everyone i have a lot of code recorded
and i would like some help in making the code more compact-readable if possible

2 lines in 1?
Code:
Sheets("Sheet1").Select
Sheets("Sheet1").Name = "Data"
Sheets(Array("Sheet2", "Sheet3")).Select
ActiveWindow.SelectedSheets.Delete
ActiveWorkbook.SaveAs "C:\Data.xls"

......

Columns("G:G").Select
    ActiveWindow.FreezePanes = True
    Columns("K:L").Insert Shift:=xlToRight
    Columns("N:N").Insert Shift:=xlToRight
    Range("K1").Formula = "F1"
    Range("L1").Formula = "F2"
    Range("N1").Formula = "F3"
    Range("K1").Select
    Selection.AutoFilter
    Workbooks.Open Filename:="C:\Info.xls"
    Worksheets(Array("F1", "F2", "F3")).Copy Workbooks("Data.xls").Worksheets(1)
    Windows("Info.xls").Activate
    ActiveWindow.Close
    Sheets("Data").Select

sort option?
Code:
Range("A1:W" & LR).Sort Key1:=Range("F2"), Order1:=xlAscending, Header:= _
        xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
        DataOption1:=xlSortNormal



and finally the recorded part for external data:
Code:
With ActiveSheet.QueryTables.Add(Connection:=Array( _
        "OLEDB;Provider=Microsoft.Jet.OLEDB.4.0;Password="""";User ID=Admin;Data Source=C:\AllSales.m" _
        , _
        "db;Mode=Share Deny Write;Extended Properties="""";Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Database Passw" _
        , _
        "ord="""";Jet OLEDB:Engine Type=5;Jet OLEDB:Database Locking Mode=0;Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Trans" _
        , _
        "actions=1;Jet OLEDB:New Database Password="""";Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:D" _
        , _
        "on't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False" _
        ), Destination:=Range("A1"))
        .CommandType = xlCmdTable
        .CommandText = Array("Helen")
        .Name = "db1"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .BackgroundQuery = True
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .PreserveColumnInfo = True
        .SourceDataFile = _
        "C:\AllSales.mdb"
        .Refresh BackgroundQuery:=False

thanks in advance for any help
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
i believe for the first ones this works just fine:
Code:
Sheets("Sheet1").Name = "Data"
instead of
Code:
Sheets("Sheet1").Select
Sheets("Sheet1").Name = "Data"
and...
Code:
Sheets(Array("Sheet2", "Sheet3")).Delete
instead of
Code:
Sheets(Array("Sheet2", "Sheet3")).Select
ActiveWindow.SelectedSheets.Delete
 
Upvote 0

Forum statistics

Threads
1,224,574
Messages
6,179,629
Members
452,933
Latest member
patv

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top