View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Sheeloo[_3_] Sheeloo[_3_] is offline
external usenet poster
 
Posts: 1,805
Default macro to find data from one sheet & copy in another sheet

Try the macro below
(See inline comments for explanation)

Sub copyMacro()
Dim lastRow1, lastRow2 As Long
Dim i, k, startRow As Long

'Change Long to String in the statement below if CUSTNO are not pure numbers
Dim custNo As Long

'Change 15 to the first row on CUSTOMER sheet where you want the customer
data to start
startRow = 15
k = startRow


With Worksheets("DueList")
lastRow1 = .Cells(.Rows.Count, "A").End(xlUp).Row
End With

With Worksheets("Customer")
lastRow2 = .Cells(.Rows.Count, "D").End(xlUp).Row
.Range(Cells(startRow, 1), Cells(lastRow2, 15)).ClearContents
End With

custNo = Worksheets("Customer").Range("B3").Value

For i = 1 To lastRow1
If Worksheets("DueList").Cells(i, 1) = custNo Then
'Change A to the Col Letter you want to start on

With Worksheets("DueList")
..Range(.Cells(i, 1), .Cells(i, 15)).Copy _
Destination:=Worksheets("Customer").Range("A" & k)
k = k + 1
End With
End If
Next

k = k - 1
'if the data ends at row 70, then put sum at d72 total, e72 total & f72 total
Worksheets("Customer").Range("D" & (k + 2)).Value = "=Sum(D" & startRow &
":D" & k & ")"
Worksheets("Customer").Range("E" & (k + 2)).Value = "=Sum(E" & startRow &
":E" & k & ")"
Worksheets("Customer").Range("F" & (k + 2)).Value = "=Sum(F" & startRow &
":F" & k & ")"

' I have left the following steps for you to write
'select c3:f75(f72+3) as print range (for preview or print);
'format the c15:f72 with borders
Worksheets("Customer").Range("A1").Select
MsgBox "Processing Complete"


End Sub

"Eddy Stan" wrote:

hi
Kindly help me with macro to save time & file size.
I am having customer bills listed in duelist sheet rows 18000
listed date wise, the columns headings at 5 as cust-no, biz, region,
location, custgroup, customer, bildate, misdate, bilamt, paidamt, due amt and
remarks
Now in customer sheet-Customer number will be put at cell b3
(rows 4 to 14 has address subject etc.,) i have column title at row15
macro to be place in a button.
macro start
i need customer no# in b3 found in range cust_no in the duelist sheet, then
from duelist sheet copy matching row's, billno, billdate, billamt, paidamt,
balamt, remarks and paste in query sheet start at row 15 column
c15(billdate),d15(billamount),e15(paidamt),f15(due amt), g15 (remarks), then
next find at row 16,...so on. suppose
if the data ends at row 70, then put sum at d72 total, e72 total & f72 total
then
select c3:f75(f72+3) as print range (for preview or print);
format the c15:f72 with borders
then
close macro
i have done this by putting formulas from row 15 to row 700, expecting
maximum due bills 685. Used formula in duelist in afresh column to find
matching rows.
Then picked them in customer sheet
so the file size is very big like 40mb so take much time. i have used macro
to print customer letter with bill details, but it take much time. i hope
macro will take less space & time.
advance thanks for help, quick help is appreciated.