G
Guest
I've got Type Mismatch error message while I'm running the following code
(It happens half way through, so I think the code can work ok, but I don't know why it stops right in the middle!!!!
How can I improve the code and solve the problem? Pls Help!!! Thanks!!!
Function Copy(ByVal RowNum As String
Sheets("Region").Selec
C1 =
For S2 = 2 To 5000
If Workbooks("Test.xls").Worksheets("Region").Cells(S2, 1) = "" Then Exit For
If Right(Workbooks("Test.xls").Worksheets("Region").Cells(S2, 3), 3) _ <----- It stop right here
= Workbooks("Test.xls").Worksheets("Macro").Cells(RowNum, 4)
And Right(Workbooks("Test.xls").Worksheets("Region").Cells(S2, 3), 3)
<> "South" The
For S3 = 1 To 3
Worksheets("Region").Cells(C1, S3)
= Workbooks("Test.xls").Worksheets("Region").Cells(S2, S3
Next S
C1 = C1 +
ElseIf Left(Workbooks("Test.xls").Worksheets("Region").Cells(S2, 3), 4)
= Workbooks("Test.xls").Worksheets("Macro").Cells(RowNum, 5) The
For S3 = 1 To 3
Worksheets("Region").Cells(C1, S3)
= Workbooks("Test.xls").Worksheets("Region").Cells(S2, S3
Next S
C1 = C1 +
End I
Next S
End Functio
(It happens half way through, so I think the code can work ok, but I don't know why it stops right in the middle!!!!
How can I improve the code and solve the problem? Pls Help!!! Thanks!!!
Function Copy(ByVal RowNum As String
Sheets("Region").Selec
C1 =
For S2 = 2 To 5000
If Workbooks("Test.xls").Worksheets("Region").Cells(S2, 1) = "" Then Exit For
If Right(Workbooks("Test.xls").Worksheets("Region").Cells(S2, 3), 3) _ <----- It stop right here
= Workbooks("Test.xls").Worksheets("Macro").Cells(RowNum, 4)
And Right(Workbooks("Test.xls").Worksheets("Region").Cells(S2, 3), 3)
<> "South" The
For S3 = 1 To 3
Worksheets("Region").Cells(C1, S3)
= Workbooks("Test.xls").Worksheets("Region").Cells(S2, S3
Next S
C1 = C1 +
ElseIf Left(Workbooks("Test.xls").Worksheets("Region").Cells(S2, 3), 4)
= Workbooks("Test.xls").Worksheets("Macro").Cells(RowNum, 5) The
For S3 = 1 To 3
Worksheets("Region").Cells(C1, S3)
= Workbooks("Test.xls").Worksheets("Region").Cells(S2, S3
Next S
C1 = C1 +
End I
Next S
End Functio