LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default If Then Else looping problem


The following code will test two conditions in a worksheet, the
copy/paste some values on that worksheet to a different workbook an
worksheet, based on the tested conditions. This is if/then/else i
nested within a For Each worksheet loop.

It works okay, except that the way I have it incrementing rows isn'
working right. It seems that it increments several times pe
worksheet, maybe something to do with the if/then/else structure..
Anyway, I'd like the pasted data to be in consecutive rows, but instea
it is spaced by varying empty rows. Any ideas what's causing this?

Thanks... here's the code...

Sub concatenate2()
'On Error GoTo LASTSHEET
Application.ScreenUpdating = False
Dim Wkbk As Workbook
Dim wksht As Worksheet
Dim destWks As Worksheet
Dim destCell As Range
Dim drow As Integer

Set Wkbk = Workbooks("ajx.xls")
drow = 3

For Each wksht In Wkbk.Worksheets

If wksht.Range("K5") = 500 And wksht.Range("G7") = "UP" Then
Set destWks = Workbooks("combined2.xls").Worksheets("sheet1")
ElseIf wksht.Range("K5") = 500 And wksht.Range("G7") = "DOWN" Then
Set destWks = Workbooks("combined2.xls").Worksheets("sheet2")
ElseIf wksht.Range("K5") = 1000 And wksht.Range("G7") = "UP" Then
Set destWks = Workbooks("combined2.xls").Worksheets("sheet3")
ElseIf wksht.Range("K5") = 1000 And wksht.Range("G7") = "DOWN
Then
Set destWks = Workbooks("combined2.xls").Worksheets("sheet4")
ElseIf wksht.Range("K5") = 2000 And wksht.Range("G7") = "UP" Then
Set destWks = Workbooks("combined2.xls").Worksheets("sheet5")
ElseIf wksht.Range("K5") = 2000 And wksht.Range("G7") = "DOWN
Then
Set destWks = Workbooks("combined2.xls").Worksheets("sheet6")
ElseIf wksht.Range("K5") = 4000 And wksht.Range("G7") = "UP" Then
Set destWks = Workbooks("combined2.xls").Worksheets("sheet7")
Else
Set destWks = Workbooks("combined2.xls").Worksheets("sheet8")
End If

With destWks
Set destCell = .Cells(drow, 1)
End With

wksht.Range("J12:O12").Copy
destCell.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone
SkipBlanks _
:=False, Transpose:=False

drow = drow + 1
Next
LASTSHEET:
End Su

--
Kieran102
-----------------------------------------------------------------------
Kieran1028's Profile: http://www.excelforum.com/member.php...fo&userid=1567
View this thread: http://www.excelforum.com/showthread.php?threadid=27746

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Scrolling Looping Problem Nick Wakeham Excel Discussion (Misc queries) 0 June 12th 07 01:42 PM
Macro looping problem. [email protected] Excel Discussion (Misc queries) 8 October 26th 06 02:44 PM
Problem with Looping and Output Dnk Excel Programming 3 September 30th 04 10:24 PM
complex looping problem Max Bialystock Excel Programming 16 April 10th 04 01:56 PM
Looping Problem Todd Huttenstine[_3_] Excel Programming 5 January 25th 04 12:51 AM


All times are GMT +1. The time now is 06:49 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"