Solved

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

Posted on 2011-03-11
2
241 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Excel conversion issue with Sql server 14 45
Hlookup formula help 14 19
change VBA to show result in cells rather than debug.print 4 34
COPY from excel to notepad 3 32
As with any other System Center product, the installation for the Authoring Tool can be quite a pain sometimes. This article serves to help you avoid making these mistakes and hopefully save you a ton of time on troubleshooting :)  Step 1: Make sur…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

932 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now