Set column range based on cell value

AdamCons

New Member
Joined
May 24, 2021
Messages
2
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hi All

I've searched all day, but I cannot find answer (or I'm too lame to understand). I want to copy values from column from one sheet ('New week'!B) to column 'Week'!XX. Range 'Week'!XX has to be dynamic and should read column name from cell 'New week"!N18 (values in cell DI, AZ - outcome 'Week'!DI, 'Week'!AZ etc.).

I'll appreciate yours help.

Non dynamic code
VBA Code:
Sub CopyWeek()

Dim j
j = 5

Do Until Range("'New week'!A" & j) = ""

Range("'Week'!DI" & j) = Range("'New week'!B" & j)

j = j + 1
Loop

End Sub
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
I made solution code for 3 columns. Can anyone check if it can be write in better way? I'm just doing first steps.

VBA Code:
Sub CopyWeek()

Dim j
j = 5

Dim qty As Variant
qty = Range("'New week'!O13")

Dim qtybxs As Variant
qtybxs = Range("'New week'!P13")

Dim qtyplts As Variant
qtyplts = Range("'New week'!Q13")


Do Until Range("'New week'!A" & j) = ""

Worksheets("Week").Cells(j, qty).Value = Range("'New week'!B" & j)

Worksheets("Week").Cells(j, qtybxs).Value = Range("'New week'!C" & j)

Worksheets("Week").Cells(j, qtyplts).Value = Range("'New week'!D" & j)

j = j + 1
Loop

End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,214,875
Messages
6,122,046
Members
449,063
Latest member
ak94

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