alivenwell
10-01-2007, 07:43 AM
Hi, I am a newbie to Vba, and was hoping if anyone can help me on my loop that i made.
Right. My loop, starting with the first country it finds in this customer file, it searches for a country in a second file and copies a range of data and pastes it into the customer file. However, there are some countries that are not on the second file and I would like the macro to skip to the next country instead.
Here's my loop:
With sht1
colnum = 12
mainwb = ActiveWorkbook.Name
otherwb = Workbooks("Country.xls").Name
lastrow = LastRowWithData()
For x = 7 To lastrow
If Range("D" & x).Value <> "" Then
country = Trim(Range("D" & x).Value)
colnum = 12
For y = 1 To 16
Workbooks(otherwb).Activate
Cells.Find(country).Select
Range("C" & ActiveCell.Row, "I" & ActiveCell.Row).Copy
sht1.Activate
Cells(x, colnum).PasteSpecial xlPasteValues
Application.CutCopyMode = False
colnum = colnum + 7
Next
End If
Hope someone can help. Thanks
Right. My loop, starting with the first country it finds in this customer file, it searches for a country in a second file and copies a range of data and pastes it into the customer file. However, there are some countries that are not on the second file and I would like the macro to skip to the next country instead.
Here's my loop:
With sht1
colnum = 12
mainwb = ActiveWorkbook.Name
otherwb = Workbooks("Country.xls").Name
lastrow = LastRowWithData()
For x = 7 To lastrow
If Range("D" & x).Value <> "" Then
country = Trim(Range("D" & x).Value)
colnum = 12
For y = 1 To 16
Workbooks(otherwb).Activate
Cells.Find(country).Select
Range("C" & ActiveCell.Row, "I" & ActiveCell.Row).Copy
sht1.Activate
Cells(x, colnum).PasteSpecial xlPasteValues
Application.CutCopyMode = False
colnum = colnum + 7
Next
End If
Hope someone can help. Thanks