First Blank Column

djr8yk

Board Regular
Joined
May 19, 2015
Messages
58
Hi,

I'm trying to find the first blank cell in a row and attain its column. I know this question has been posted a million times on all of the forums, but for the life of me I can't seem to get it to work. I've seen many different solutions, but can somebody tell me why this doesn't work?

Code:
With ActiveWorkbook.Worksheets("Set-Up Data") ' choose the worksheet called "Set-Up Data"
      Dim col As Integer
      col = .Cells(2, Columns.count).End(xlToLeft).Column
      .Cells(1, col) = name
      .Cells(2, col) = "Necessary?"
End With
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
This
col = .Cells(2, Columns.count).End(xlToLeft).Column
Does NOT find the first blank column...
It actually finds the LAST NON-Blank column.

You'd just have to add 1 to make it the first blank after (to the right of) the last non blank.

col = .Cells(2, Columns.count).End(xlToLeft).Column + 1
 
Upvote 0
Hi,

I'm trying to find the first blank cell in a row and attain its column. I know this question has been posted a million times on all of the forums, but for the life of me I can't seem to get it to work. I've seen many different solutions, but can somebody tell me why this doesn't work?

Code:
With ActiveWorkbook.Worksheets("Set-Up Data") ' choose the worksheet called "Set-Up Data"
      Dim col As Integer
      col = .Cells(2, Columns.count).End(xlToLeft)[B][COLOR="#FF0000"].Offset(, 1)[/COLOR][/B].Column
      .Cells(1, col) = name
      .Cells(2, col) = "Necessary?"
End With
You want the blank cell located after the end of your data, correct? If so, then try adding what I show in red above.

Edit Note: ... or just add one to the value you already calculated like Jonmo1 told in the message immediately before mine.
 
Last edited:
Upvote 0
But the rest looks okay? It's still not doing what I need it to, but that's probably a problem elsewhere.
 
Upvote 0
Probably a stupid question, but is there any advantage to using the Offset function as opposed to just adding one, as suggested above? I would assume offset is essentially doing just that but more elegantly
 
Upvote 0
Probably a stupid question, but is there any advantage to using the Offset function as opposed to just adding one, as suggested above? I would assume offset is essentially doing just that but more elegantly
You did not see the Edit Note I added to my message yet, did you? Use what Jonmo1 posted to do... the Offset method would be useful if you needed a reference to that cell, but since all you want is a column number, adding one to what you had already calculated is probably the easier method to use.
 
Upvote 0
But the rest looks okay? It's still not doing what I need it to.
Can you clarify ?

What DOES it do? How is that different from what you WANT it to do?
Is Row 2 filled with Formulas? And they are returning "" at the end (to the right) ?
 
Upvote 0
You're right, Rick. I hadn't seen the edit. Thank you for your quick response, as always.
 
Upvote 0
Jonmo,
Sorry for the vague response. I'll try to explain briefly but I don't expect you to have a response without seeing the rest of my code.
I currently have a sheet that will store data from a UserForm that is generated by a series of user prompts. Once it's generated, I want to run through the sheet and store the responses in a worksheet. Currently, in this worksheet, I have a few columns that correspond to certain values, but the rest have to be updated to correspond with the generated UserForm. That's why I'm trying to find the last column. Unfortunately, it's still not writing to these cells as I've tried to do, but like I said, there's a lot of code in this and it's probably an error elsewhere. Still relatively new to VBA, learning the syntax as I go!
Thank you for your help.
 
Upvote 0

Forum statistics

Threads
1,214,830
Messages
6,121,835
Members
449,051
Latest member
excelquestion515

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