Question about look up

sey

New Member
Joined
Apr 28, 2011
Messages
35
Hi

I have a question for looping.
This is all my code, and ("eersterij") means firstrow. In first row he find all dimensions. u can see on the first image, firstrow is selected, second row is the row under first row and finally there is a third row under second row. (But there can be more rows)

Here you see my code:

In the images u see:

First he is looking for how many rows there are ( now there are 3 rows).
Then he paste the dimensions from the first row in a template (you can see in the second picture).
Then he paste the template in a worksheet.
Then he cleans the dimensions in the template and he copy this template 2 times more.
You can see in the last picture : 3 rows with dimensions, so 3 pictures of a template.

But what i want is this:
First he copy the dimensions from the first row in the template and paste the template in that other worksheet. ( then he cleans the dimenions in the original template)
THEN he copy the dimensions of the SECOND row and paste them in the original template and paste the template under the second one in a new worksheet.( then he cleans the dimenions in the original template)
THEN the third one.
(IF there are more rows then ofcourse for fourth, fifth... row too.)

The code :
For Each acell In Range("eersterij")
If acell.Value > 0 Then
acell.copy
y = acell.Value / x

I need to write something other in place of ("eersterij") , so he goes to the second row and third row too, without writing this code 3 times.


Code:
Sub copypastelookupalin1()
Dim acell As Range
Dim teller As Integer
Dim y As Double
Dim bcell As Range
Dim counter As Integer

 counter = 0
 teller = 0
' kijken hoeveel keer een template moet gemaakt worden
    Sheets("SETUP").Activate
    Range("begincellll").Select
    ActiveCell = ActiveCell.Offset(1, 1)

    For Each bcell In Range("Bereik")
        If IsEmpty(bcell) Then
            'bcell = blank
        Else: 'bcell = 1
            counter = counter + 1
            
' maak een cel om te starten
Sheets("kwnie").Activate
Range("D20").Name = "afmt100"
' bereken het aantal cellen die nodig zijn
Z = Range("totalelengte2") / 100
'bereken de schaal
a = Z / 83
' de afstand die 1 cel zal bevatten
Sheets("SETUP").Activate
Range("totalelengte2").Select
x = Range("totalelengte2").Value / Z

For Each acell In Range("eersterij")
If acell.Value > 0 Then
acell.copy
y = acell.Value / x

Sheets("kwnie").Activate
Range("afmt100").Activate
'ActiveCell.Value = "|"
ActiveCell.Offset(0, Round(teller + y / 2)).Select
teller = teller + y
ActiveSheet.PasteSpecial
End If
Next acell
' afbeelding aanpassen aan de schaal
    
  ActiveSheet.Shapes("afbeeldingg").Select
  ActiveSheet.Shapes("afbeeldingg").Delete
  Sheets("stuktekening gordingenang").Select
  ActiveSheet.Shapes("object 1").copy
  Sheets("kwnie").Select
  Range("A24").Select
  ActiveSheet.Paste
  Selection.Name = "afbeeldingg"
  ActiveSheet.Shapes("afbeeldingg").Select
  Application.CutCopyMode = False
  Selection.ShapeRange.LockAspectRatio = msoTrue
  Selection.ShapeRange.ScaleHeight a, msoFalse, msoScaleFromTopLeft
  Selection.ShapeRange.ScaleWidth a, msoFalse, msoScaleFromTopLeft
    
' cellen opmaken voor waarden mooi in te plaatsen
Range("voorbeeld").Select
Selection.copy
Range("invulplaatsen").Select
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
' templates kopieren en onder elkaar polaatsen
            Sheets("kwnie").Activate
            Range("Print_Area").CopyPicture
            Sheets("Stuktekeningtemplate").Activate
            Range("startcel").Select
           
            ActiveCell.Offset(((counter - 1) * 50) + 1, 0).Select
            ActiveSheet.PasteSpecial
                
' cellen legen voor volgende copy
Sheets("kwnie").Activate
Range("invulplaatsen").Select
Selection.ClearContents
     
        End If
    Next bcell
  
    Sheets("SETUP").Activate
    Range("begincellll").Select
    ActiveCell.FormulaR1C1 = counter
    
End Sub



2q3yalx.jpg
[/IMG]
k2jnm.jpg
[/IMG]hi,
27yq3k1.jpg
[/IMG]
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
I know it's a long question, but i'm searching already 1 and a half full day to do this.
I know my English isn't that good, so if something isn't clear, just ask i will explain again with pleasure.

I will apriciate any help very much.
Thank you for ur time


Kind regards
Sey
 
Upvote 0
I will try to translate the extra information in green

Code:
Dim acell As Range
Dim teller As Integer
Dim y As Double
Dim bcell As Range
Dim counter As Integer

 counter = 0
 teller = 0
[COLOR=seagreen]'To look up how many template there need to be made (copied and paste)[/COLOR]
    Sheets("SETUP").Activate
    Range("begincellll").Select
    ActiveCell = ActiveCell.Offset(1, 1)

    For Each bcell In Range("Bereik")
        If IsEmpty(bcell) Then
            'bcell = blank
        Else: 'bcell = 1
            counter = counter + 1
            
[COLOR=seagreen]To make a cell, to have a startplace in my worksheet (were i paste the first dimension)[/COLOR]
[COLOR=black]Sheets[/COLOR]("kwnie").Activate
Range("D20").Name = "afmt100"
'[COLOR=seagreen]To calculate how many cell's i wil need (for the dimensions)[/COLOR]
Z = Range("totalelengte2") / 100
'bereken de schaal
a = Z / 83
[COLOR=seagreen]' The distance that 1 cell will have as value[/COLOR]
Sheets("SETUP").Activate
Range("totalelengte2").Select
x = Range("totalelengte2").Value / Z

For Each acell In Range("eersterij")
If acell.Value > 0 Then
acell.copy
y = acell.Value / x

Sheets("kwnie").Activate
Range("afmt100").Activate
ActiveCell.Offset(0, Round(teller + y / 2)).Select
teller = teller + y
ActiveSheet.PasteSpecial
End If
Next acell
'[COLOR=#2e8b57]adjust the image to the scale[/COLOR]    
  ActiveSheet.Shapes("afbeeldingg").Select
  ActiveSheet.Shapes("afbeeldingg").Delete
  Sheets("stuktekening gordingenang").Select
  ActiveSheet.Shapes("object 1").copy
  Sheets("kwnie").Select
  Range("A24").Select
  ActiveSheet.Paste
  Selection.Name = "afbeeldingg"
  ActiveSheet.Shapes("afbeeldingg").Select
  Application.CutCopyMode = False
  Selection.ShapeRange.LockAspectRatio = msoTrue
  Selection.ShapeRange.ScaleHeight a, msoFalse, msoScaleFromTopLeft
  Selection.ShapeRange.ScaleWidth a, msoFalse, msoScaleFromTopLeft
    
' [COLOR=seagreen]to make up the cell's, so i can place the dimensions in it[/COLOR]
Range("voorbeeld").Select
Selection.copy
Range("invulplaatsen").Select
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
' [COLOR=seagreen]To copy the templates and paste them under each other[/COLOR]
            Sheets("kwnie").Activate
            Range("Print_Area").CopyPicture
            Sheets("Stuktekeningtemplate").Activate
            Range("startcel").Select
           
            ActiveCell.Offset(((counter - 1) * 50) + 1, 0).Select
            ActiveSheet.PasteSpecial
                
'[COLOR=seagreen]To clean the cells, for the next dimensions[/COLOR]
Sheets("kwnie").Activate
Range("invulplaatsen").Select
Selection.ClearContents
     
        End If
    Next bcell
  
    Sheets("SETUP").Activate
    Range("begincellll").Select
    ActiveCell.FormulaR1C1 = counter
    
End Sub

I know it's a long question, but i'm searching already 1 and a half full day to do this.
I know my English isn't that good, so if something isn't clear, just ask i will explain again with pleasure.

I will apriciate any help very much.
Thank you for ur time


Kind regards
Sey
 
Upvote 0
I don't have time to look at this in detail, hopefully this will get you started.

Code:
For xyz = 0 to counter - 1
For Each acell In Range("eersterij").Offset(xyz, 0)

 
Next
Next
 
Upvote 0
No problem, I already apriciate that you try to help.
Thanks! I will have a look :biggrin:
I don't have time to look at this in detail, hopefully this will get you started.

Code:
For xyz = 0 to counter - 1
For Each acell In Range("eersterij").Offset(xyz, 0)
 
 
Next
Next
 
Upvote 0
I changed like u suggested, but it doens't really work, it still copy only the values from the firstrow, not from second and third.
Any way thank you for your suggestion! :biggrin:
Any other suggestions?

Kind Regards
Code:
Sub allesin1()

Dim acell As Range
Dim teller As Integer
Dim y As Double
Dim bcell As Range
Dim counter As Integer

 counter = 0
 teller = 0
' kijken hoeveel keer een template moet gemaakt worden
    Sheets("SETUP").Activate
    Range("begincellll").Select
    ActiveCell = ActiveCell.Offset(1, 1)

    For Each bcell In Range("Bereik")
        If IsEmpty(bcell) Then
            'bcell = blank
        Else: 'bcell = 1
            counter = counter + 1
            
' maak een cel om te starten
Sheets("kwnie").Activate
Range("D20").Name = "afmt100"

For xyz = 0 To counter - 1
' bereken het aantal cellen die nodig zijn
Z = Range("totalelengte1").Offset(xyz, 0) / 100
'bereken de schaal
a = Z / 83
' de afstand die 1 cel zal bevatten
Sheets("SETUP").Activate
Range("totalelengte1").Offset(xyz, 0).Select
x = Range("totalelengte1").Offset(xyz, 0).Value / Z
 

For Each acell In Range("eersterij").Offset(xyz, 0)
If acell.Value > 0 Then
acell.copy
y = acell.Value / x

Sheets("kwnie").Activate
Range("afmt100").Activate
'ActiveCell.Value = "|"
ActiveCell.Offset(0, Round(teller + y / 2)).Select
teller = teller + y
ActiveSheet.PasteSpecial
End If
Next acell

' afbeelding aanpassen aan de schaal
    
  ActiveSheet.Shapes("afbeeldingg").Select
  ActiveSheet.Shapes("afbeeldingg").Delete
  Sheets("stuktekening gordingenang").Select
  ActiveSheet.Shapes("object 1").copy
  Sheets("kwnie").Select
  Range("A24").Select
  ActiveSheet.Paste
  Selection.Name = "afbeeldingg"
  ActiveSheet.Shapes("afbeeldingg").Select
  Application.CutCopyMode = False
  Selection.ShapeRange.LockAspectRatio = msoTrue
  Selection.ShapeRange.ScaleHeight a, msoFalse, msoScaleFromTopLeft
  Selection.ShapeRange.ScaleWidth a, msoFalse, msoScaleFromTopLeft
    
' cellen opmaken voor waarden mooi in te plaatsen
Range("voorbeeld").Select
Selection.copy
Range("invulplaatsen").Select
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
' templates kopieren en onder elkaar polaatsen
            Sheets("kwnie").Activate
            Range("Print_Area").CopyPicture
            Sheets("Stuktekeningtemplate").Activate
            Range("startcel").Select
           
            ActiveCell.Offset(((counter - 1) * 50) + 1, 0).Select
            ActiveSheet.PasteSpecial
                
' cellen legen voor volgende copy
Sheets("kwnie").Activate
Range("invulplaatsen").Select
Selection.ClearContents
     
        
        Next xyz
        End If
    Next bcell
  
    Sheets("SETUP").Activate
    Range("begincellll").Select
    ActiveCell.FormulaR1C1 = counter
    
End Sub
No problem, I already apriciate that you try to help.
Thanks! I will have a look :biggrin:
 
Upvote 0
Only had another quick glance,

It looks like it should process all 3 rows, but is pasting to the wrong place.

Code:
Range("D20").Name = "afmt100"

Is the cause of that, each time the code runs it will start at D20, you need something like

Code:
Range("D20").Offset(newcounter,0).Name = "afmt100"

Then you need a way to count how many rows below "amft100" the next template should start, which should go in place of ??? below.

Code:
newcounter = newcounter + ???
Next xyz

There may be other problems that I haven't noticed.
 
Upvote 0
But i have an original template.
And in that original template (which can be found in sheets("kwnie") there
is the afmt100 cell. The "afmt100" is the cell that i use always as the first cell for the dimensions, as u can see on this picture.
I don't need to paste it to another place, because afmt100 ( and the cells on the right side off afmt100) always be cleared with the code:
Code:
Sheets("kwnie").Activate
Range("invulplaatsen").Select
Selection.ClearContents

"Invulplaatsen" are all that long small cells above the image.
I use that original template for, pasting all the dimensions in it, then i copy and past it to another work sheet. THEN i clear all the cells in the ORIGINAL template and THEN i will fill it again with the dimensions of the second row. and so on....

Or did i misunderstand u?

Sorry if i didn't explain my problem that good, i'm new here and i try to do my best. and thank you for all the help u try to give me. I apriciate that.

Kind regards
Sey
b8wbph.jpg
[/IMG]
Only had another quick glance,

It looks like it should process all 3 rows, but is pasting to the wrong place.

Code:
Range("D20").Name = "afmt100"

Is the cause of that, each time the code runs it will start at D20, you need something like

Code:
Range("D20").Offset(newcounter,0).Name = "afmt100"

Then you need a way to count how many rows below "amft100" the next template should start, which should go in place of ??? below.

Code:
newcounter = newcounter + ???
Next xyz

There may be other problems that I haven't noticed.
 
Upvote 0
Sorry, it makes sense now, I was looking at the wrong sheet in your first example.

Starting again, is "eersterij" always S21:AB21 ?

Maybe a better approach would be

Code:
For xzy = 21 To counter + 20
For abc = 19 to 28
Set aCell = Sheets("SETUP").Cells(xyz, abc).Address(0, 0)

instead of the eersterij.offset method I suggested earlier.

Note: the syntax on the last line may need correcting.
 
Upvote 0
yes, and "tweederij" (secondrow) is always s22:AB22 and so on.

I don't really understand ur code, can u explain a little bit, if it's not a problem for u?:biggrin:




Sorry, it makes sense now, I was looking at the wrong sheet in your first example.

Starting again, is "eersterij" always S21:AB21 ?

Maybe a better approach would be

Code:
For xzy = 21 To counter + 20
For abc = 19 to 28
Set aCell = Sheets("SETUP").Cells(xyz, abc).Address(0, 0)

instead of the eersterij.offset method I suggested earlier.

Note: the syntax on the last line may need correcting.
 
Upvote 0

Forum statistics

Threads
1,224,581
Messages
6,179,668
Members
452,936
Latest member
anamikabhargaw

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top