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]
 
If both refer to the same cell then yes, 17 is correct, I was thinking that they would be different.

Most of it comes from a lucky guess lol.

The problem is a couple of lines above the error,

Code:
x = Z = Sheets("SETUP").Cells(xyz, 17) / Z

Should be
Code:
x = Sheets("SETUP").Cells(xyz, 17) / Z

Hopefully it's getting close now :)
 
Upvote 0

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Haha :p Then you are a good gambler lol :stickouttounge:
Yea no ERRORS!
But still not working correctly lol....:(
Maybe i better send my excel to u, if you are still not tired and bored :stickouttounge:
It's much easier to guess:p

Anyway thank you for all your efforts!!!
If both refer to the same cell then yes, 17 is correct, I was thinking that they would be different.

Most of it comes from a lucky guess lol.

The problem is a couple of lines above the error,

Code:
x = Z = Sheets("SETUP").Cells(xyz, 17) / Z

Should be
Code:
x = Sheets("SETUP").Cells(xyz, 17) / Z

Hopefully it's getting close now :)
 
Upvote 0
Where does it appear to be going wrong now?

edit:-

the line
Code:
Next bcell
needs to be moved up, it needs to be below the line

Code:
If Not (IsEmpty(bcell)) Then .....
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,584
Messages
6,179,691
Members
452,938
Latest member
babeneker

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