VBA - simple one. How do I stop a loop when a column is reached?

RockandGrohl

Well-known Member
Joined
Aug 1, 2018
Messages
788
Office Version
  1. 2010
Platform
  1. Windows
Hi all,

We all know the traditional "Do until cells(activecell.row, "A").value = "" "

Meaning, stop when the first blank row is reached.

I'm trying to loop through a range of columns, offsetting every 11 columns, and I want to stop when either the active cell is blank or the column reaches DD


I'm really rusty with VBA at the moment and I can't remember how to do anything, so I'd like to avoid anything more complex for the moment.

I would expect the following to work:

VBA Code:
Do until activecell.value = "" or activecell.column = "DD" 

--doing stuff here--

activecell.offset(0,11).activate
Loop

Instead I get a type mismatch. Any ideas? Thanks.
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Try this.
VBA Code:
Do Until ActiveCell.Value = "" Or ActiveCell.Column >= Columns("DD").Column

    '--doing stuff here--

    ActiveCell.Offset(0, 11).Activate

Loop
 
Upvote 0
Now how the hell do I paste to a cell below the active row?

Why has my brain just deleted VBA...

VBA Code:
    ActiveCell.Offset(1).EntireRow.Insert
    Range("A" & ActiveCell.Row, "O" & ActiveCell.Row).Copy
    Range("A" & ActiveCell.Row + 1).Paste
 
Upvote 0
One way

VBA Code:
Do Until ActiveCell.Value = ""
    If ActiveCell.Column >= Range("DD1").Column Then Exit Do
    ActiveCell.Offset(0, 11).Activate
    'etc
Loop
 
Upvote 0

Forum statistics

Threads
1,214,402
Messages
6,119,304
Members
448,886
Latest member
GBCTeacher

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