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

RockandGrohl

Active Member
Joined
Aug 1, 2018
Messages
497
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.
 

Some videos you may like

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,216
Office Version
  1. 365
Platform
  1. Windows
Try this.
VBA Code:
Do Until ActiveCell.Value = "" Or ActiveCell.Column >= Columns("DD").Column

    '--doing stuff here--

    ActiveCell.Offset(0, 11).Activate

Loop
 

RockandGrohl

Active Member
Joined
Aug 1, 2018
Messages
497
Office Version
  1. 2010
Platform
  1. Windows
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
 

Yongle

Well-known Member
Joined
Mar 11, 2015
Messages
6,975
Office Version
  1. 365
Platform
  1. Windows
One way

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

Watch MrExcel Video

Forum statistics

Threads
1,122,262
Messages
5,595,154
Members
413,971
Latest member
User786

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
Top