Solved

Loop through column when naming ranges, but skipping empty cells until end of loop.

Posted on 2011-03-11
2
245 Views
Last Modified: 2012-05-11
I have the below code and with the help of Sid, it works as I wish.  However, now I need for it to actually go through the i = 6 to 100, but if it encounters a blank cell, simply go to the next cell.  Between 6 and 100 are several blank fields separating data groupings, but I need to be sure the all non-blank fields are used.  
With Worksheets("Datasource")
    For i = 6 To 15
        .Range(strColumnRange & i).Name = .Range(strColumnRangeText & i).Value
    Next
End With

Open in new window

0
Comment
Question by:ssmith94015
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 30

Accepted Solution

by:
SiddharthRout earned 500 total points
ID: 35109967
Like this?

With Worksheets("Datasource")
    For i = 6 To 100
        If Len(Trim(.Range(strColumnRangeText & i).Value)) <> 0 Then _
        .Range(strColumnRange & i).Name = .Range(strColumnRangeText & i).Value
    Next
End With

Open in new window


Sid
0
 

Author Closing Comment

by:ssmith94015
ID: 35110080
Yes that works.  Thank you again.  It has been a long time since I programmed Excel and your help has been signifcant on this project.  I normally program databases, but the client wants all this in Excel and it has been a challenge!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question