Find cell

Hi,

I have the following headings in excel
Date      spread      Date       spread
                  
I want to move loop through the row of headings to find a blank column for displaying the data.
What code can i use for this.

Thanks
camper12Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
Your question is not clear at least to me.
Please explain your requirement clearly and if possible please upload a sample workbook to demonstrate your requirement in the workbook itself.
camper12Author Commented:
example.jpg
I want to loop through the columns until I come across column E because it is a fresh column and does not have a heading. I will then populate column E with data.

Thanks
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
Well if you are trying to find the first empty column in header row1, you may try this......

Sub FindFirstEmptyColumnInHeaderRow()
Dim emptyCol As Long
emptyCol = Cells(1, Columns.Count).End(xlToLeft).Column + 1     'Assuming the Row1 is the header row
MsgBox emptyCol
End Sub

Open in new window


Is this what you are trying to achieve?
Active Protection takes the fight to cryptojacking

While there were several headline-grabbing ransomware attacks during in 2017, another big threat started appearing at the same time that didn’t get the same coverage – illicit cryptomining.

Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
I didn't see your reply but I think I guessed it correctly.
Once you find the emptyCol with the help of the above code, you can use it in your code.
camper12Author Commented:
Does not work when it is the first column. It returns 2.

Thanks
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
In that case you may try something like this.......

Sub FindFirstEmptyColumnInHeaderRow()
Dim emptyCol As Long
emptyCol = Cells(1, Columns.Count).End(xlToLeft).Column
If emptyCol <> 1 Then emptyCol = emptyCol + 1
MsgBox emptyCol
End Sub

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
Did it work for you?
If yes and takes care of your original question, please mark the thread as Solved by accepting the answer.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.