Home > Software design >  Borders and Formatting as Table
Borders and Formatting as Table

Time:08-06

I developed the following code which should do two things, but I am have problems on it:

`' ************* Places Boarder Around the Document****************

myrange = Cells(Rows.Count, 6).End(xlUp).Address

        Sheets("LTXN Report").Range(Selection, ("a1:" & myrange)).Select
        ActiveSheet.Range("A1:" & myrange).BorderAround ColorIndex:=1, Weight:=xlThick`

What this SHOULD do is put a bold border around the doc, however, it does not do the bottom edge of the data. Is there something I am doing wrong there?

Next:

'************* Formats Data as Table ******************************

MyTableRange = Range("a4:" & myrange).Address

        Range("A4:F4").Select
        Range(Selection, Selection.End(xlDown)).Select
        ActiveSheet.ListObjects.Add(xlSrcRange, Range("MyTableRange"), , xlYes).Name = "NewTable"
        ActiveSheet.ListObjects("NewTable").TableStyle = "TableStyleMedium1"

This should format all the actual data in the document into a table. I am specifically having and issue with the range ("MyTableRange") any idea what I am doing wrong there?

Bonus: I am ultimately exporting to to PDF and I would love it if I could have the table header appear on each page. Is that possible?

Also, I THINK if I solve the border situation above it will still be broken because when it prints to PDF it wont show the bottom edge of the border on each page will it? Is there a way around that?

Thanks for the help folks!

EDIT:: It may help to know that the data I am formatting is being imported and will always be between A1 : F???. The variable that is unknown is how many rows each time which is why I am not using a constant range.

CodePudding user response:

Being more assertive you can do like this (relative to the first code posted):

myrange = Cells(Rows.Count, 6).End(xlUp).Address

With Sheets("LTXN Report")
    .Select ' or .Activate
    .Range("A1:" & myrange).BorderAround ColorIndex:=1, Weight:=xlThick
End With

The second code has a typo: Range("MyTableRange"). Remove the quotes as it is a variable.

  • Related