+ Reply to Thread
Results 1 to 2 of 2

Using a Macro to format spreadsheet - warning, there's a twist number of columns varies

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    03-08-2011
    Location
    London
    MS-Off Ver
    2019
    Posts
    449

    Using a Macro to format spreadsheet - warning, there's a twist number of columns varies

    Hello again everyone!

    I'm creating a workbook for someone so all they have to do is press buttons to operate macro's to do their stuff.

    Unfortunately, the number of tabs that are imported from Column C can vary between 2, 27 or even more. It's not fixed. However, When the data is imported it resembles the file 20150330 Example Worksheet Without formatting

    What I want to do is make it achieve 20150330 Example Worksheet With formatting

    How do I achieve the following:
    Set Column Width for Column A (User ID) to Auto
    Set Column Width for Column B (User Names and Descriptions) to 40 and wrap text
    Set Column Width for all the columns up to the "User Parent Company" (in this instance Column G) to 3
    Set Column Width for "User Parent Company", "SME Approver", "SME Approver Email", "SME Approver Comments", SME Approver Enter Removal Ticket No" (in this instance Columns G, H, I, L and M) to 20
    Set Column Width for "User is a current employee ...." and "Date" (in this instance Columns J and K) to 15
    Set Cells A1 and B1 to centre left
    Rotate text in cells between (but not including) "User Names and Descriptions" and "User's Parent Company" by 90 degrees (in this instance Cells C1 - F1)
    Centre all the columns between (but not including) "User Names and Descriptions" and "User's Parent Company" (in this instance columns C - F)

    Please remember, after column B the number of columns prior to "User's Parent Company" may vary

    Any help would be greatly appreciated.

    Thanks all

  2. #2
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Using a Macro to format spreadsheet - warning, there's a twist number of columns varie

    Change
        With Sheets("User to System Matrix").Cells(1).Resize(UBound(a, 1), UBound(a, 2))
            .CurrentRegion.ClearContents
            .Value = a
            Sheets("Verification Details").Cells(1).CurrentRegion.Rows(1).Copy .Cells(1, .Columns.Count + 1)
            With .Columns(.Columns.Count + 1).Offset(1).Resize(.Rows.Count - 1)
    '            .Formula = "=iferror(vlookup(a2,'Known Users'!a:b,2,false),"""")"
                .Formula = "=if(vlookup(a2,'Known Users'!a:b,2,false)="""","""",vlookup(a2,'Known Users'!a:b,2,false))"
                .FormatConditions.Delete
                .FormatConditions.Add Type:=xlExpression, Formula1:="=" & .Cells(1).Address(0, 0) & "="""""
                .FormatConditions(1).Interior.Color = vbRed
            End With
        End With
    to
        With Sheets("User to System Matrix").Cells(1).Resize(UBound(a, 1), UBound(a, 2))
            .CurrentRegion.ClearContents
            .Value = a
            With .Cells(1, 3).Resize(, UBound(a, 2) - 2)
                .Orientation = 90
                .Columns.AutoFit
            End With
            Sheets("Verification Details").Cells(1).CurrentRegion.Rows(1).Copy
            With .Cells(1, .Columns.Count + 1)
                .PasteSpecial 8
                .PasteSpecial
            End With
            With .Columns(.Columns.Count + 1).Offset(1).Resize(.Rows.Count - 1)
    '            .Formula = "=iferror(vlookup(a2,'Known Users'!a:b,2,false),"""")"
                .Formula = "=if(vlookup(a2,'Known Users'!a:b,2,false)="""","""",vlookup(a2,'Known Users'!a:b,2,false))"
                .FormatConditions.Delete
                .FormatConditions.Add Type:=xlExpression, Formula1:="=" & .Cells(1).Address(0, 0) & "="""""
                .FormatConditions(1).Interior.Color = vbRed
            End With
        End With

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Sending data from textbox/userform to excel spreadsheet row (row varies)
    By t0mps in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-25-2014, 06:46 AM
  2. Replies: 4
    Last Post: 09-04-2013, 09:58 AM
  3. Replies: 1
    Last Post: 08-15-2011, 11:20 AM
  4. number to time format when digit length varies
    By UM Win in forum Excel General
    Replies: 5
    Last Post: 12-08-2005, 10:00 PM
  5. number to time format when digit length varies
    By UM Win in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-08-2005, 10:00 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1