Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 661
Default help with loops in code,

continuing saga of worksheets printing and planning

I have 2 worksheets printing and planning
printing extends from a1:ae35
planning extends from a1:bh61

I have the following code that works perfectly for a range e3:e61 But when
I come to change it to another range it does not work....

I want it to extend the range to check for values in columns g, i, k
........ (every second column until bg) in planning and return results in
columns d, e, f, g etc to column ae

I still only want to compare values in column A in sh.printing and still
return the corresponding value in column A in sh.planning.

I ve spent hours fiddling around with loops and things, but no luck.

Here is the code that uses range e3:e61:

Public Sub test2()
Dim cfind As Range
Dim x As Range
Dim cell As Range
Dim myrange As Range
With Worksheets("printing")
Set myrange = .Range(.Range("a3"), .Cells(Rows.Count, 1).End(xlUp))
End With
For Each cell In myrange
With Worksheets("planning").Range("e3:e61")
Set cfind = .Cells.Find(what:=cell.Value, lookat:=xlWhole)
If Not cfind Is Nothing Then
Set x = .Cells(cfind.Row, 1)
Worksheets("printing").Activate
cfind.End(xlToLeft).Copy cell.Offset(0, 3)
Else
cell.Offset(0, 3).Value = ""
End If
End With
Next cell
End Sub

Thanks in advance

Paul
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default help with loops in code,

I can't visualize what you want so you may send a workbook to MY email below
along another sheet showing what the desired results would be. Copy THIS
email to another sheet in the file.

--
Don Guillett
SalesAid Software


"Paul" wrote in message
...
continuing saga of worksheets printing and planning

I have 2 worksheets printing and planning
printing extends from a1:ae35
planning extends from a1:bh61

I have the following code that works perfectly for a range e3:e61 But
when
I come to change it to another range it does not work....

I want it to extend the range to check for values in columns g, i, k
....... (every second column until bg) in planning and return results in
columns d, e, f, g etc to column ae

I still only want to compare values in column A in sh.printing and still
return the corresponding value in column A in sh.planning.

I ve spent hours fiddling around with loops and things, but no luck.

Here is the code that uses range e3:e61:

Public Sub test2()
Dim cfind As Range
Dim x As Range
Dim cell As Range
Dim myrange As Range
With Worksheets("printing")
Set myrange = .Range(.Range("a3"), .Cells(Rows.Count, 1).End(xlUp))
End With
For Each cell In myrange
With Worksheets("planning").Range("e3:e61")
Set cfind = .Cells.Find(what:=cell.Value, lookat:=xlWhole)
If Not cfind Is Nothing Then
Set x = .Cells(cfind.Row, 1)
Worksheets("printing").Activate
cfind.End(xlToLeft).Copy cell.Offset(0, 3)
Else
cell.Offset(0, 3).Value = ""
End If
End With
Next cell
End Sub

Thanks in advance

Paul



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,588
Default help with loops in code,

Paul,

One clarification:
cfind.End(xlToLeft).Copy cell.Offset(0, 3)


Where does the xlToLeft take you? Should this always go to column A?

Tim


"Paul" wrote in message ...
continuing saga of worksheets printing and planning

I have 2 worksheets printing and planning
printing extends from a1:ae35
planning extends from a1:bh61

I have the following code that works perfectly for a range e3:e61 But when
I come to change it to another range it does not work....

I want it to extend the range to check for values in columns g, i, k
....... (every second column until bg) in planning and return results in
columns d, e, f, g etc to column ae

I still only want to compare values in column A in sh.printing and still
return the corresponding value in column A in sh.planning.

I ve spent hours fiddling around with loops and things, but no luck.

Here is the code that uses range e3:e61:

Public Sub test2()
Dim cfind As Range
Dim x As Range
Dim cell As Range
Dim myrange As Range
With Worksheets("printing")
Set myrange = .Range(.Range("a3"), .Cells(Rows.Count, 1).End(xlUp))
End With
For Each cell In myrange
With Worksheets("planning").Range("e3:e61")
Set cfind = .Cells.Find(what:=cell.Value, lookat:=xlWhole)
If Not cfind Is Nothing Then
Set x = .Cells(cfind.Row, 1)
Worksheets("printing").Activate
cfind.End(xlToLeft).Copy cell.Offset(0, 3)
Else
cell.Offset(0, 3).Value = ""
End If
End With
Next cell
End Sub

Thanks in advance

Paul



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default help with loops in code,

Public Sub test2()
Dim cfind As Range
Dim rng1 As Range
Dim cell As Range
Dim myrange As Range
Dim icol As Long, i As Long
With Worksheets("printing")
Set myrange = .Range(.Range("a3"), .Cells(Rows.Count, 1).End(xlUp))
End With
With Worksheets("planning")
Set rng1 = .Range("e3")
For i = 7 To 59 Step 2
Set rng1 = Union(rng1, .Cells(3, i))
Next
Set rng1 = Intersect(rng1.EntireColumn, _
.Range("3:61").EntireRow)
End With
For Each cell In myrange
With rng1
Set cfind = .Cells.Find(what:=cell.Value, lookat:=xlWhole)
If Not cfind Is Nothing Then
icol = ((cfind.Column - 3) / 2) + 3
rng1.Parent.Cells(cfind.Row, icol).Copy _
cell.Parent.Cells(cell.Row, "AE")
End If
Else
cell.Offset(0, 3).Value = ""
End If
End With
Next cell
End Sub

--
Regards,
Tom Ogilvy

"Paul" wrote in message
...
continuing saga of worksheets printing and planning

I have 2 worksheets printing and planning
printing extends from a1:ae35
planning extends from a1:bh61

I have the following code that works perfectly for a range e3:e61 But

when
I come to change it to another range it does not work....

I want it to extend the range to check for values in columns g, i, k
....... (every second column until bg) in planning and return results in
columns d, e, f, g etc to column ae

I still only want to compare values in column A in sh.printing and still
return the corresponding value in column A in sh.planning.

I ve spent hours fiddling around with loops and things, but no luck.

Here is the code that uses range e3:e61:

Public Sub test2()
Dim cfind As Range
Dim x As Range
Dim cell As Range
Dim myrange As Range
With Worksheets("printing")
Set myrange = .Range(.Range("a3"), .Cells(Rows.Count, 1).End(xlUp))
End With
For Each cell In myrange
With Worksheets("planning").Range("e3:e61")
Set cfind = .Cells.Find(what:=cell.Value, lookat:=xlWhole)
If Not cfind Is Nothing Then
Set x = .Cells(cfind.Row, 1)
Worksheets("printing").Activate
cfind.End(xlToLeft).Copy cell.Offset(0, 3)
Else
cell.Offset(0, 3).Value = ""
End If
End With
Next cell
End Sub

Thanks in advance

Paul



Reply
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
code loops 1024 times not what i ask Rob Hargreaves[_2_] Excel Programming 3 August 7th 05 11:36 AM
ADO & Loops: error in code? Santiago[_2_] Excel Programming 2 July 28th 05 07:25 PM
for each loops adncmm1980[_3_] Excel Programming 1 October 4th 04 12:56 PM
Help on writing code more efficiently (Loops) Kathryn[_5_] Excel Programming 3 May 25th 04 08:45 PM
Loops Snow[_2_] Excel Programming 2 May 13th 04 09:48 PM


All times are GMT +1. The time now is 04:14 PM.

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

About Us

"It's about Microsoft Excel"