PDA

View Full Version : Macro SoS!



bobby
08-19-2014, 12:06 PM
Hi,

how to use Macro to automate the work as:
1. recognize the name and copy its value, then paste to second sheet where has the same name
2. repeat the work for each coloum
1214012139
As you can see I copy the data from first sheet and then paste to second sheet my code is

=IFERROR(INDEX($C$11, Match(Sheet1!$B$11,Sheet2! A5,0))," ")
It works..

I just cant put it into macro

Some one please give me some hint,,, Thanks

Bob Phillips
08-19-2014, 01:10 PM
I would do it with formulas, but


Public Sub CopyValues()
Dim rowTotals As Long
Dim colLast As Long
Dim rowMatch As Long
Dim i As Long

With Worksheets("Copy")

colLast = .Cells(3, .Columns.Count).End(xlToLeft).Column
For i = 1 To colLast

If .Cells(5, i).Value <> "" Then

rowMatch = 0
On Error Resume Next
rowMatch = Application.Match(.Cells(5, i).Value, Worksheets("Paste").Columns(1), 0)
On Error GoTo 0
If rowMatch > 0 Then

Worksheets("Paste").Cells(rowMatch, "D").Value = .Cells(11, i + 1).Value
Worksheets("Paste").Cells(rowMatch, "F").Value = .Cells(11, i + 1).Value - .Cells(15, i + 1).Value
End If
End If
Next i
End With
End Sub

bobby
08-19-2014, 01:46 PM
Thanks alot for the reply! Are you using loop in this case?

Bob Phillips
08-20-2014, 04:53 AM
Can't you see that I am, a For ... Next loop.

bobby
08-20-2014, 06:07 AM
Sorrry i know nothing about VBA... my apology...

bobby
08-20-2014, 06:35 AM
Thanks xld. I just ran your Code. It works. But I forgot to mention that each invoice has to only contain one type of bill.. If i want to copy paste administration Fees to invoice form, then i have to use another empty sheet... How can i do that? Thank you Xld

Bob Phillips
08-20-2014, 11:14 AM
Sorry, I am not sure what that means.

bobby
08-20-2014, 11:28 AM
:hi:Its ok. I think i just did not explain to you well.. I have one template ( for invoice preparation ). Everyday i receive lots of Bills ( Consulting fees, Legal fess etc) I have to prepare invoice form for each bill. Since i m fed up with manual work, I want to run a macro to do the job for me. But first I need to let macro know which column i want to extract the data from. Then Paste to the invoice form wherever row it belongs ... i dont know if its clearer or even worse.. ^^ THanks Xld,,