Extend columns in a do until loop

Allan91

New Member
Joined
Dec 17, 2020
Messages
33
Office Version
  1. 2019
Platform
  1. Windows
I have written this code which draws data from a sheet to another with a do until loop but it does it only for 1 column (column U, the 21st column). I want to be able to perform this for 5 columns (columns U, V,W,X,Y). How should I change my code?

VBA Code:
Sub DrawData()

Dim x As Integer

x = 1

Do While Worksheets("Clean Data_I").Cells(x, 21).Value <> ""
Worksheets("Clean Data_I2").Cells(x, 1).Value = Worksheets("Clean Data_I").Cells(x, 21).Value
x = x + 1
Loop

End Sub
 
Oops, it should be
VBA Code:
With .Range("U1:Y" & .Range("U" & Rows.Count).End(xlUp).Row)
Also with this code the formula blanks should not create a problem.
Hey! This works perfectly.

Thanks a ton Fluff!
 
Upvote 0

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Glad we could help & thanks for the feedback.
 
Upvote 0
Please disregard this message. I thanked twice thinking the first of didn't post :)

Oops, it should be
VBA Code:
With .Range("U1:Y" & .Range("U" & Rows.Count).End(xlUp).Row)
Also with this code the formula blanks should not create a problem.
Hey this works!

Thanks a ton Fluff.
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,875
Members
452,363
Latest member
merico17

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