Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default Simple VBA range loop?

I have two liked size ranges. 10 rows x 14 columns. I need to write a loop
routine that examines each cell in the 1st range and if it finds a "1", then
copy the contents of a static cell into the corresponding cell in the second
range.

This seems pretty straightforward, but I'm not getting anywhere (Obviously
I'm a newbie).

TIA
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,560
Default Simple VBA range loop?

Hi,

You need to be a little more specific. Find the 1 and put it at the end of
your second range, just the 1 or the contents of the row, where the 1 is
found? You say "contents of a static cell", then maybe just one variable?

Both ranges are exactly the same size with a one to one correspondance
between the ranges, but they do not contain the same contents or you would
arlread have a 1 in the second range?

David

"fedude" wrote:

I have two liked size ranges. 10 rows x 14 columns. I need to write a loop
routine that examines each cell in the 1st range and if it finds a "1", then
copy the contents of a static cell into the corresponding cell in the second
range.

This seems pretty straightforward, but I'm not getting anywhere (Obviously
I'm a newbie).

TIA

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default Simple VBA range loop?

Sorry... noob you know.

Two exact sized ranges 10x14. One range (1st) is completely empty, the
second range has ones or zeros in every cell. The loop needs to examine
the contents of every cell in the 2nd range (ones and zeros) and if it finds
a "1" in a cell, the loop should copy the contents of a single independent
cell to the corresponding cell in the 1st array. The single independent
cell to copy contains an image in it and this same image will be copied to
every corresponding cell in the 1st array if the 2nd arrya has a "1" in it.

Does this help??



"David" wrote:

Hi,

You need to be a little more specific. Find the 1 and put it at the end of
your second range, just the 1 or the contents of the row, where the 1 is
found? You say "contents of a static cell", then maybe just one variable?

Both ranges are exactly the same size with a one to one correspondance
between the ranges, but they do not contain the same contents or you would
arlread have a 1 in the second range?

David

"fedude" wrote:

I have two liked size ranges. 10 rows x 14 columns. I need to write a loop
routine that examines each cell in the 1st range and if it finds a "1", then
copy the contents of a static cell into the corresponding cell in the second
range.

This seems pretty straightforward, but I'm not getting anywhere (Obviously
I'm a newbie).

TIA

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Simple VBA range loop?

Oops, my previous post had you right up to the "contains an image".

Cells don't contain images - they can contain only values and formulae.

Images reside on the drawing layer "above" the cells.

So perhaps something like:

Dim picPicture As Picture
Dim picNew As Picture
Dim rDest As Range
Dim i As Long

Application.ScreenUpdating = False

Set picPicture = ActiveSheet.Pictures("Picture 1")

With Range("A1").Resize(10, 20)
Set rDest = Range("A20").Resize(.Rows.Count, .Columns.Count)
For i = 1 To .Count
If IsNumeric(.Cells(i).Value) Then
If .Cells(i).Value = 1 Then
Set picNew = picPicture.Duplicate
With rDest(i)
picNew.Top = .Top
picNew.Left = .Left
picNew.Height = .Height
picNew.Width = .Width
picNew.Placement = xlMoveAndSize
End With
End If
End If
Next i
End With

Application.ScreenUpdating = True



In article ,
fedude wrote:

Sorry... noob you know.

Two exact sized ranges 10x14. One range (1st) is completely empty, the
second range has ones or zeros in every cell. The loop needs to examine
the contents of every cell in the 2nd range (ones and zeros) and if it finds
a "1" in a cell, the loop should copy the contents of a single independent
cell to the corresponding cell in the 1st array. The single independent
cell to copy contains an image in it and this same image will be copied to
every corresponding cell in the 1st array if the 2nd arrya has a "1" in it.

Does this help??



"David" wrote:

Hi,

You need to be a little more specific. Find the 1 and put it at the end of
your second range, just the 1 or the contents of the row, where the 1 is
found? You say "contents of a static cell", then maybe just one variable?

Both ranges are exactly the same size with a one to one correspondance
between the ranges, but they do not contain the same contents or you would
arlread have a 1 in the second range?

David

"fedude" wrote:

I have two liked size ranges. 10 rows x 14 columns. I need to write a
loop
routine that examines each cell in the 1st range and if it finds a "1",
then
copy the contents of a static cell into the corresponding cell in the
second
range.

This seems pretty straightforward, but I'm not getting anywhere
(Obviously
I'm a newbie).

TIA

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default Simple VBA range loop?

ARGH! Not knowing that about the pictures is what has been killing me.
Thanks for the knowledge. Impressive.

This works beautifully. Mucho thanks!

Just for my own information, can you explain what this part of the code is
doing:

picNew.Top = .Top
picNew.Left = .Left
picNew.Height = .Height
picNew.Width = .Width

"JE McGimpsey" wrote:

Oops, my previous post had you right up to the "contains an image".

Cells don't contain images - they can contain only values and formulae.

Images reside on the drawing layer "above" the cells.

So perhaps something like:

Dim picPicture As Picture
Dim picNew As Picture
Dim rDest As Range
Dim i As Long

Application.ScreenUpdating = False

Set picPicture = ActiveSheet.Pictures("Picture 1")

With Range("A1").Resize(10, 20)
Set rDest = Range("A20").Resize(.Rows.Count, .Columns.Count)
For i = 1 To .Count
If IsNumeric(.Cells(i).Value) Then
If .Cells(i).Value = 1 Then
Set picNew = picPicture.Duplicate
With rDest(i)
picNew.Top = .Top
picNew.Left = .Left
picNew.Height = .Height
picNew.Width = .Width
picNew.Placement = xlMoveAndSize
End With
End If
End If
Next i
End With

Application.ScreenUpdating = True



In article ,
fedude wrote:

Sorry... noob you know.

Two exact sized ranges 10x14. One range (1st) is completely empty, the
second range has ones or zeros in every cell. The loop needs to examine
the contents of every cell in the 2nd range (ones and zeros) and if it finds
a "1" in a cell, the loop should copy the contents of a single independent
cell to the corresponding cell in the 1st array. The single independent
cell to copy contains an image in it and this same image will be copied to
every corresponding cell in the 1st array if the 2nd arrya has a "1" in it.

Does this help??



"David" wrote:

Hi,

You need to be a little more specific. Find the 1 and put it at the end of
your second range, just the 1 or the contents of the row, where the 1 is
found? You say "contents of a static cell", then maybe just one variable?

Both ranges are exactly the same size with a one to one correspondance
between the ranges, but they do not contain the same contents or you would
arlread have a 1 in the second range?

David

"fedude" wrote:

I have two liked size ranges. 10 rows x 14 columns. I need to write a
loop
routine that examines each cell in the 1st range and if it finds a "1",
then
copy the contents of a static cell into the corresponding cell in the
second
range.

This seems pretty straightforward, but I'm not getting anywhere
(Obviously
I'm a newbie).

TIA




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Simple VBA range loop?

It resizes the new picture (picNew) to the size of the destination cell.

May be overkill if all your cells are the same size, but allows for
varying sized rows/columns.


In article ,
fedude wrote:

Just for my own information, can you explain what this part of the code is
doing:

picNew.Top = .Top
picNew.Left = .Left
picNew.Height = .Height
picNew.Width = .Width

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Simple VBA range loop?

One way:

Dim vStatic As Variant
Dim rDest As Range
Dim i As Long

vStatic = Range("Z100").Value 'Change to suit
With Range("A1").Resize(10, 14)
Set rDest = Range("A20").Resize(.Rows.Count, .Columns.Count)
For i = 1 To .Count
If IsNumeric(.Cells(i).Value) Then _
If .Cells(i).Value = 1 Then rDest(i).Value = vStatic
Next i
End With



In article ,
fedude wrote:

I have two liked size ranges. 10 rows x 14 columns. I need to write a loop
routine that examines each cell in the 1st range and if it finds a "1", then
copy the contents of a static cell into the corresponding cell in the second
range.

This seems pretty straightforward, but I'm not getting anywhere (Obviously
I'm a newbie).

TIA

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
simple loop needed please Alan Excel Discussion (Misc queries) 1 May 5th 10 06:33 PM
Simple Loop Help Please pianoman[_24_] Excel Programming 0 May 24th 06 02:34 PM
Simple Loop Help Please HBF Excel Programming 0 May 24th 06 02:30 PM
Simple loop? bushtor Excel Programming 3 September 13th 05 01:45 PM
Some help w/ simple loop, please? terry b Excel Programming 6 February 6th 05 06:17 PM


All times are GMT +1. The time now is 12:31 PM.

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"