Cannot get my Macro to run through range

Oscar23

New Member
Joined
Nov 29, 2023
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Doing an assignment for Uni, lecturer didn’t provide us with any teaching on vba.. have this code written out and when i run it it’s only giving me back the first row of each of my ranges, i can’t seem to move it down the row.
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
VBA Code:
Dim r
For Each r in ActiveSheet.Rows
r.Select
Next r
 
Upvote 0
have this code written out and when i run it it’s only giving me back the first row of each of my ranges
What code? I don't see any code in your post.
 
Upvote 0
What code? I don't see any code in your post.
What code? I don't see any code in your post.
Sub Table2()
Set MyWorksheet = Worksheets("Simulation Real (4)")
MyWorksheet.Activate
SampleSize = Range("N14")
For Row = 1 To SampleSize
x = Range("M16:M26")
y = Range("N16:N26")
Z = Range("O16:O26")
Cells(28 + i, "M") = x
Cells(28 + i, "N") = y
Cells(28 + i, "O") = Z
Next Row
Set SimulatedValues = Range(Range("M29"), Cells(28 + SampleSize, "M"))
 
Upvote 0
What is the purpose of your macro?
Do you want to copy the values of ranges M16:M26, N16:N26 and O16:O26 to the corresponding ranges M29:M39, N29:N39,
O29:O39?
Please explain.

Artik
 
Upvote 0
This part of your code is definitely problematic:
x = Range("M16:M26")
y = Range("N16:N26")
Z = Range("O16:O26")
Cells(28 + i, "M") = x
Cells(28 + i, "N") = y
Cells(28 + i, "O") = Z
Are x, y, and Z supposed to be ranges or values?
If ranges, you need to use the word "Set" with them, i.e.
VBA Code:
Set x = Range("M16:M26")
If values, it doesn't make sense, as x cannot be 11 different values at once.
You either need to populate it as an array, or loop through each value one-by-one.
 
Upvote 0

Forum statistics

Threads
1,215,711
Messages
6,126,401
Members
449,312
Latest member
sweetfriend9

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