Excel print page misses first column

dshafique

Board Regular
Joined
Jun 19, 2017
Messages
171
Hi guys! i made a macros that sorts people's names. it has 2 columns, the names, and the desk number. however, when i go to print it, the print space doesnt include the first column, only shows the desk space column. and the first page that prints is blank. to fix it, i have to go to page layout each time to manually choose A1 and change the left margin to 3.2

is there a way to automate this process? the data is dynamic, so the number of rows will change each month.
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
i have two macros, one sorts it by first name, and one sorts it by last name

FIRST NAME
Code:
Sub FirstName()
'
' Macro2 Macro
'
   Cells.AutoFilter
    Range("A1").Select
    Set Rng = Range(Range("A1"), Range("A1").SpecialCells(xlLastCell))
    Set tbl = ActiveSheet.ListObjects.Add(xlSrcRange, Rng, , xlYes)
    tbl.Name = "lTable"
    tbl.TableStyle = "TableStyleLight8"
    
    Range("A1").Select
    currentColumn = 1
    While currentColumn <= ActiveSheet.UsedRange.Columns.Count
        columnHeading = ActiveSheet.UsedRange.Cells(1, currentColumn).Value
        keepColumn = False
        If columnHeading = "Employee Name" Then keepColumn = True
        If columnHeading = "Space #" Then keepColumn = True
        If keepColumn Then
            currentColumn = currentColumn + 1
        Else
            ActiveSheet.Columns(currentColumn).Delete
        End If
        If (ActiveSheet.UsedRange.Address = "$A$1") And (ActiveSheet.Range("$A$1").Text = "") Then Exit Sub
    Wend
    
    arrColOrder = Array("Employee Name", "Space#")
    counter = 1
    Application.ScreenUpdating = False
    For ndx = LBound(arrColOrder) To UBound(arrColOrder)
        Set Found = Rows("1:1").Find(arrColOrder(ndx), LookIn:=xlValues, LookAt:=xlWhole, _
                          SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:=False)
        If Not Found Is Nothing Then
            If Found.Column <> counter Then
                Found.EntireColumn.Cut
                Columns(counter).Insert Shift:=xlToRight
                Application.CutCopyMode = False
            End If
            counter = counter + 1
        End If
    Next ndx
    Application.ScreenUpdating = True
    
'
    'Deletes the entire row within the selection if the ENTIRE row contains no data.


Range("lTable[Employee Name]").Select
Dim i As Long




    With Application


        .Calculation = xlCalculationManual


        .ScreenUpdating = False




    For i = Selection.Rows.Count To 1 Step -1


        If WorksheetFunction.CountA(Selection.Rows(i)) = 0 Then


            Selection.Rows(i).EntireRow.Delete


        End If


    Next i


        .Calculation = xlCalculationAutomatic


        .ScreenUpdating = True


    End With
 


ActiveSheet.Buttons.Add(321.75, 37.5, 120, 42.75).Select
    Selection.OnAction = "LastName"
    Selection.Characters.Text = "Last Name"
    With Selection.Characters(Start:=1, Length:=9).Font
        .Name = "Calibri"
        .FontStyle = "Regular"
        .Size = 11
        .Strikethrough = False
        .Superscript = False
        .Subscript = False
        .OutlineFont = False
        .Shadow = False
        .Underline = xlUnderlineStyleNone
        .ColorIndex = 1
    End With
    ActiveSheet.Shapes.Range(Array("Button 2")).Select
    With Selection
        .Placement = xlFreeFloating
        .PrintObject = False
    End With


ActiveWorkbook.Worksheets("Adams -09").ListObjects("lTable").Sort.SortFields. _
        Clear
    ActiveWorkbook.Worksheets("Adams -09").ListObjects("lTable").Sort.SortFields. _
        Add Key:=Range("lTable[[#All],[Employee Name]]"), SortOn:=xlSortOnValues, _
        Order:=xlAscending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("Adams -09").ListObjects("lTable").Sort
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With


   Range("A1").Select
   
   sFName = Application.GetSaveAsFilename
If sFName <> "False" Then ActiveWorkbook.SaveAs sFName
   
End Sub


LAST NAME

Code:
Sub LastName()
'
' Macro2 Macro
'
  
    
    Range("C2").Select
   ActiveCell.FormulaR1C1 = _
        "=IF(ISNUMBER(SEARCH("" "",RC[-2]))=TRUE,RIGHT(RC[-2],LEN(RC[-2])-FIND("" "",RC[-2]))& "" "" & LEFT(RC[-2],FIND("" "",RC[-2])-1),RC[-2])"
    ActiveCell.Copy
    Range(Selection, Selection.End(xlDown)).Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
    Range("C3").Select
    Columns("C:C").ColumnWidth = 13.29
    Columns("C:C").EntireColumn.AutoFit
    ActiveWindow.SmallScroll Down:=-12
    Range("C2").Select
    Range("lTable[Column1]").Select
    Selection.Copy
    Range("lTable[Employee Name]").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Columns("C:C").Select
    Application.CutCopyMode = False
    Selection.Delete Shift:=xlToLeft
    ActiveWorkbook.Worksheets("Adams -09").ListObjects("lTable").Sort.SortFields. _
        Clear
    ActiveWorkbook.Worksheets("Adams -09").ListObjects("lTable").Sort.SortFields. _
        Add Key:=Range("lTable[[#All],[Employee Name]]"), SortOn:=xlSortOnValues, _
        Order:=xlAscending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("Adams -09").ListObjects("lTable").Sort
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
   Range("A1").Select
   
   sFName = Application.GetSaveAsFilename
If sFName <> "False" Then ActiveWorkbook.SaveAs sFName
   
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,250
Members
452,623
Latest member
Techenthusiast

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