Problem with loop, nest loop

LukiiMaxim96

New Member
Joined
May 18, 2021
Messages
9
Office Version
  1. 365
Platform
  1. Windows
Hi! I need to loop through a dynamic data set, only the range in which the data are entered is given.

I need to loop through every cell and copy the value to the end of another column. I totally managed that for the first column but now I am stuck with telling excel to increment the row and run the loop again until a certain number is reached. I tried to accomplish that with a nested for next loop but that doesnt work... Any help?

I basically need to insert a variable that increments by one after the initial loop is fullfiled in the 3rd line: Offset(-2 -b,0)

Here is what ive got so far:
VBA Code:
For a = 0 To CountaColumnsResult - 1
lRow5B = Sheet5.Range("B" & Rows.Count).End(xlUp).Row
Sheet4.Range("K10").End(xlToRight).Offset(-2, a).Copy
Sheet5.Range("B" & lRow5B + 1).PasteSpecial xlPasteValues
Next

Help is highly appreciated!
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
VBA Code:
For b = 0 To CountaRowsResult
    For a = 0 To CountaColumnsResult - 1
    lRow5B = Tabelle5.Range("B" & Rows.Count).End(xlUp).Row
    Tabelle4.Cells(10 + b, 11).End(xlToRight).Offset(-2 - b, a).Copy
    Tabelle5.Range("B" & lRow5B + 1).PasteSpecial xlPasteValues
    Next a
Next b

this is my brightest try.. this cannot be to hard..
 
Upvote 0
I solved it myself:
VBA Code:
For t = 10 To CountaRowsResult + 9
    For z = 1 To CountaColumnsResult
    Tabelle4.Cells(t, 11).Offset(-t + 8, z).Copy
    lRow5B = Tabelle5.Range("B" & Rows.Count).End(xlUp).Row
    Tabelle5.Range("B" & lRow5B + 1).PasteSpecial xlPasteValues
    Next
Next
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,636
Latest member
laura12345

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