Excel macro - Copy a region of cells - max row - max column

Post Reply
wwj
Posts: 2497
Joined: 27 Jan 2007 08:16

Excel macro - Copy a region of cells - max row - max column

Post by wwj »

Code: Select all


    ' Copy 1st BC Report.
    maxRow = Sheets(inSht1).Cells(Rows.Count, "A").End(xlUp).Row
    
    Sheets(inSht1).Range(Sheets(inSht1).Cells(4, "A"), Sheets(inSht1).Cells(maxRow, "K")).Copy _
            Destination:=Sheets(outSht).Cells(2, "A")

    maxCol = Sheets(outSht).Cells(3, Columns.Count).End(xlToLeft).Column

wwj
Posts: 2497
Joined: 27 Jan 2007 08:16

Re: Excel macro - Copy a region of cells - max row - max col

Post by wwj »

Convert column letter to its corresponding number.

Code: Select all


minCol = Range("Q" & 1).Column

wwj
Posts: 2497
Joined: 27 Jan 2007 08:16

Re: Excel macro - Copy a region of cells - max row - max col

Post by wwj »

Copy a range of cells.

Code: Select all


    ' Copy Time.
    maxRow = Sheets(outSht).Cells(Rows.Count, "M").End(xlUp).Row
    
    Sheets(outSht).Range(Cells(2, "M"), Cells(maxRow, "M")).Copy _
            Destination:=Sheets(outSht).Cells(2, "P")
            
    ' Copy Reach no.
    maxRow = Sheets(outSht).Cells(Rows.Count, "N").End(xlUp).Row
    Range("N2:N" & maxRow).Select
    Selection.Copy
    Range("Q1").Select
    Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
        False, Transpose:=True
    Range("Q2").Select
    Selection.Clear
    
wwj
Posts: 2497
Joined: 27 Jan 2007 08:16

Re: Excel macro - Copy a region of cells - max row - max column

Post by wwj »

Code: Select all


'   [2] Prev. run information.
    lastRow = Sheets(outSheet).Cells(Rows.Count, "A").End(xlUp).Row
    lastTime = Sheets(outSheet).Cells(lastRow, "A")
    outCell = "A" & lastRow + 1

'   [3] Append the BC Report's contents
    lastRowIn = Sheets(inputSheet).Cells(Rows.Count, "A").End(xlUp).Row
    inRange = "A4:K" & lastRowIn
    Sheets(inputSheet).Range(inRange).Copy Destination:=Sheets(outSheet).Cells(lastRow + 1, "A")


Post Reply