John.McLaughlin
Board Regular
- Joined
- Jul 19, 2011
- Messages
- 169
I am reusing/converting old code that found the last row.
The old code is used on my List of goods and services. When the quantity column is greater than zero, it summarizes several columns on the worksheet “invoice”
I am trying to modify that code to instead summarize one column from the list of goods and services (ITEM NO/COL I) and paste it transposed across row A of the new worksheet “packlist”.
Specifically, the code stops at;
Thanks in advance, I am barely above newbie, but a really good neighbor ?
The old code is used on my List of goods and services. When the quantity column is greater than zero, it summarizes several columns on the worksheet “invoice”
I am trying to modify that code to instead summarize one column from the list of goods and services (ITEM NO/COL I) and paste it transposed across row A of the new worksheet “packlist”.
Specifically, the code stops at;
Code:
LastColumn = DstWks.Cells(Column.Count, "1").End(xlUp).Column
Code:
Sub PostPackList()
Dim DstRng As Range
Dim DstWks As Worksheet
' Dim LastRow As Long
Dim LastColumn As Long
Dim N As Long, r As Long
Dim SrcRng As Range
Dim SrcWks As Worksheet
Application.ScreenUpdating = False
Sheets("PACKLIST").Select
' Assign the Worksheets
Set SrcWks = Worksheets("SERVICES")
Set DstWks = Worksheets("PACKLIST")
' Get all cells in the Source Range starting with row 2
Set SrcRng = SrcWks.Range("I2:I2")
LastRow = SrcWks.Cells(Rows.Count, "I").End(xlUp).Row
If LastRow < SrcRng.Row Then Exit Sub Else Set SrcRng = SrcRng.Resize(LastRow - SrcRng.Row + 1, 1)
' Find the next empty column in the Destination Range starting at column A
Set DstRng = DstWks.Range("A1")
LastColumn = DstWks.Cells(Column.Count, "1").End(xlUp).Column
Set DstRng = IIf(LastColumn < DstRng.Column, DstRng, DstRng.Offset(LastColumn - DstRng.Column + 1, 0))
' Copy the Source cells to the next empty Destination column if the Source Cell in "A" is not empty
For r = 1 To SrcRng.Rows.Count
If SrcRng.Cells(r, "A") <> "" Then
SrcRng.Rows(r).Copy DstRng.Offset(N, 0)
N = N + 1
End If
Next r
Sheets("PACKIST").Select
ActiveWorkbook.Save
Application.CutCopyMode = False
Application.ScreenUpdating = True
End Sub
Thanks in advance, I am barely above newbie, but a really good neighbor ?