Results 1 to 11 of 11

Ctrl find, copy and pasting help please (Macro code needed)

Threaded View

leanne2011 Ctrl find, copy and pasting... 11-24-2011, 08:19 AM
arlu1201 Re: Ctrl find, copy and... 11-24-2011, 09:46 AM
leanne2011 Re: Ctrl find, copy and... 11-24-2011, 10:03 AM
arlu1201 Re: Ctrl find, copy and... 11-24-2011, 10:05 AM
leanne2011 Re: Ctrl find, copy and... 11-24-2011, 10:26 AM
arlu1201 Re: Ctrl find, copy and... 11-24-2011, 11:17 AM
leanne2011 Re: Ctrl find, copy and... 11-25-2011, 04:09 AM
arlu1201 Re: Ctrl find, copy and... 11-25-2011, 06:52 AM
leanne2011 Re: Ctrl find, copy and... 11-25-2011, 07:40 AM
arlu1201 Re: Ctrl find, copy and... 11-25-2011, 09:41 AM
arlu1201 Re: Ctrl find, copy and... 11-28-2011, 10:59 AM
  1. #1
    Forum Contributor
    Join Date
    09-06-2011
    Location
    northern ireland
    MS-Off Ver
    Excel 365
    Posts
    180

    Ctrl find, copy and pasting help please (Macro code needed)

    Hi

    I attach two spreadsheets, one is "Excel Spreadsheet Header Row_1.xlsx" which is a fixed header row that has to stay in the order on the sheet. The other spreadsheet is a variable spreadsheet which changes month to month "example.xlsx". I need the data from the example.xlsx to be copy and pasted into the excel spreadsheet but not all header row items are used.

    My problem is when I search for "Salary Adj", because its not in the example.xlsx the macro stops working and I need a bit of code to rectify it. So If the column "Salary Adj" has no data in the example sheet then I want zero's in the cells within the column with the header "Salary Adj" in the Excel Spreadsheet Header Row.xlsx"

    Here is a selection of the code below:

    
    Sub parttwo()
        
        
        Workbooks.Open Filename:= _
            "N:\PAYROLL\Leanne\Private - Macro Work LB only\Excel Spreadsheet Header Row_1.xlsx"
        
        'Need to sort this out because it can't find sal adj its displaying an error
        
       
        Range("S2").Select
        Cells.Find(What:="Salary Adj", After:=ActiveCell, LookIn:=xlFormulas, _
            LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
            MatchCase:=False, SearchFormat:=False).Activate
        Range("T2").Select
        Application.CutCopyMode = False
        With Selection.Font
            .Name = "Microsoft Sans Serif"
            .FontStyle = "Regular"
            .Size = 8
            .Strikethrough = False
            .Superscript = False
            .Subscript = False
            .OutlineFont = False
            .Shadow = False
            .Underline = xlUnderlineStyleNone
            .TintAndShade = 0
            .ThemeFont = xlThemeFontNone
        End With
        With Selection.Interior
            .Pattern = xlNone
            .TintAndShade = 0
            .PatternTintAndShade = 0
        End With
        Selection.Borders(xlDiagonalDown).LineStyle = xlNone
        Selection.Borders(xlDiagonalUp).LineStyle = xlNone
        With Selection.Borders(xlEdgeLeft)
            .LineStyle = xlContinuous
            .ColorIndex = 3
            .TintAndShade = 0
            .Weight = xlThin
        End With
        Selection.Borders(xlEdgeTop).LineStyle = xlNone
        Selection.Borders(xlEdgeBottom).LineStyle = xlNone
        With Selection.Borders(xlEdgeRight)
            .LineStyle = xlContinuous
            .ColorIndex = 3
            .TintAndShade = 0
            .Weight = xlThin
        End With
        Selection.Borders(xlInsideVertical).LineStyle = xlNone
        Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
        With Selection
            .HorizontalAlignment = xlRight
            .VerticalAlignment = xlTop
            .WrapText = False
            .Orientation = 0
            .AddIndent = False
            .IndentLevel = 0
            .ShrinkToFit = False
            .ReadingOrder = xlContext
            .MergeCells = False
        End With
        Selection.NumberFormat = "0.00"
        ActiveCell.FormulaR1C1 = "0"
        Range("T2").Select
        Selection.Copy
        Range("T2:T30").Select
        ActiveSheet.Paste
    Not sure that I put the complete piece of the code in, so for car allowance the same thing happens as below

    
    
     Windows("example.xlsx").Activate
        Range("V30").Select
        
        'same for this as car allow and sal adj
        Cells.Find(What:="Holiday Pay", After:=ActiveCell, LookIn:=xlFormulas, _
            LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
            MatchCase:=False, SearchFormat:=False).Activate
        Windows("Excel Spreadsheet Header Row_1.xlsx").Activate
        Cells.Find(What:="Holiday Pay", After:=ActiveCell, LookIn:=xlFormulas, _
            LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
            MatchCase:=False, SearchFormat:=False).Activate
        Range("W2").Select
        Application.CutCopyMode = False
        With Selection.Font
            .Name = "Microsoft Sans Serif"
            .FontStyle = "Regular"
            .Size = 8
            .Strikethrough = False
            .Superscript = False
            .Subscript = False
            .OutlineFont = False
            .Shadow = False
            .Underline = xlUnderlineStyleNone
            .TintAndShade = 0
            .ThemeFont = xlThemeFontNone
        End With
        With Selection.Interior
            .Pattern = xlNone
            .TintAndShade = 0
            .PatternTintAndShade = 0
        End With
        Selection.Borders(xlDiagonalDown).LineStyle = xlNone
        Selection.Borders(xlDiagonalUp).LineStyle = xlNone
        With Selection.Borders(xlEdgeLeft)
            .LineStyle = xlContinuous
            .ColorIndex = 3
            .TintAndShade = 0
            .Weight = xlThin
        End With
        Selection.Borders(xlEdgeTop).LineStyle = xlNone
        Selection.Borders(xlEdgeBottom).LineStyle = xlNone
        With Selection.Borders(xlEdgeRight)
            .LineStyle = xlContinuous
            .ColorIndex = 3
            .TintAndShade = 0
            .Weight = xlThin
        End With
        Selection.Borders(xlInsideVertical).LineStyle = xlNone
        Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
        With Selection
            .HorizontalAlignment = xlRight
            .VerticalAlignment = xlTop
            .WrapText = False
            .Orientation = 0
            .AddIndent = False
            .IndentLevel = 0
            .ShrinkToFit = False
            .ReadingOrder = xlContext
            .MergeCells = False
        End With
        Selection.NumberFormat = "0.00"
        ActiveCell.FormulaR1C1 = "0"
        Range("W2").Select
    Attached Files Attached Files
    Last edited by leanne2011; 11-24-2011 at 08:29 AM.

Thread Information

Users Browsing this Thread

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

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