+ Reply to Thread
Results 1 to 7 of 7

Want to exit sub if range have no data

Hybrid View

HaroonSid Want to exit sub if range... 05-06-2014, 03:05 AM
sktneer Re: Want to exit sub if range... 05-06-2014, 03:18 AM
HaroonSid Re: Want to exit sub if range... 05-06-2014, 03:25 AM
hemesh Re: Want to exit sub if range... 05-06-2014, 03:30 AM
HaroonSid Re: Want to exit sub if range... 05-06-2014, 03:34 AM
sktneer Re: Want to exit sub if range... 05-06-2014, 03:37 AM
sktneer Re: Want to exit sub if range... 05-06-2014, 03:35 AM
  1. #1
    Forum Contributor HaroonSid's Avatar
    Join Date
    02-28-2014
    Location
    india
    MS-Off Ver
    Excel 2013
    Posts
    2,095

    Want to exit sub if range have no data

    hello
    i m using below code to edit cells one by one in range, but there is little problem, if there is no data in range (c10:c300) and i run code then there is coming up a debug,
    i want if there is no data in range C10:C300 then exit the sub,..

    Sub Haroon2015_RangeEditing()
    Sheets("ENTRY").Select
    Range("C10:C300").SpecialCells(xlCellTypeConstants).Select
    Dim rngCell As Range
    Dim varAns
    'For Each rngCell In Range("C10:C25")
    For Each rngCell In Selection
      varAns = InputBox(prompt:="Edit cell if wanted", Title:="Edit cell " & rngCell.Address(0, 0), Default:=rngCell.Value)
      If Not varAns = "" Then rngCell.Value = varAns
    Next rngCell
    End Sub

  2. #2
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,655

    Re: Want to exit sub if range have no data

    May be this........
    Sub Haroon2015_RangeEditing()
    Sheets("ENTRY").Select
    If WorksheetFunction.Count(Range("C10:C300")) = 0 Then Exit Sub
    Range("C10:C300").SpecialCells(xlCellTypeConstants).Select
    Dim rngCell As Range
    Dim varAns
    'For Each rngCell In Range("C10:C25")
    For Each rngCell In Selection
      varAns = InputBox(prompt:="Edit cell if wanted", Title:="Edit cell " & rngCell.Address(0, 0), Default:=rngCell.Value)
      If Not varAns = "" Then rngCell.Value = varAns
    Next rngCell
    End Sub
    Regards
    sktneer


    Treat people the way you want to be treated. Talk to people the way you want to be talked to.
    Respect is earned NOT given.

  3. #3
    Forum Contributor HaroonSid's Avatar
    Join Date
    02-28-2014
    Location
    india
    MS-Off Ver
    Excel 2013
    Posts
    2,095

    Re: Want to exit sub if range have no data

    thanx works pertect

    will add u repu

  4. #4
    Forum Expert
    Join Date
    02-19-2013
    Location
    India
    MS-Off Ver
    07/16
    Posts
    2,386

    Re: Want to exit sub if range have no data

    Haroon ! do you have only Numbers in your specified range Or You have Text Also!
    -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    WANT TO SAY THANKS, HIT ADD REPUTATION (*) AT THE BOTTOM LEFT CORNER OF THE POST

    More we learn about excel, more it shows us, how less we know about it.

    for chemistry
    https://www.youtube.com/c/chemistrybyshivaansh

  5. #5
    Forum Contributor HaroonSid's Avatar
    Join Date
    02-28-2014
    Location
    india
    MS-Off Ver
    Excel 2013
    Posts
    2,095

    Re: Want to exit sub if range have no data

    i have only text

  6. #6
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,655

    Re: Want to exit sub if range have no data

    @haroon

    If you have text only in the range then change the code to this........

    If WorksheetFunction.CountA(Range("C10:C300")) = 0 Then Exit Sub

  7. #7
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,655

    Re: Want to exit sub if range have no data

    @hemesh

    Correct point raised. If the range may contain text in that case he may change COUNT to COUNTA in the code.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. If no matching number in range then exit sub
    By wrightyrx7 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-31-2014, 10:57 AM
  2. [SOLVED] Compare two folder files - whether they exit or not and if exit then copy to another foler
    By sthiru in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-10-2012, 12:08 AM
  3. [SOLVED] Exit sub if range has ANY value
    By VBA FTW in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-12-2012, 03:21 AM
  4. How to exit a loop once the value is found in the range
    By Suety in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-28-2010, 01:30 PM
  5. Importing data - then clearing it on exit
    By Radonsheep in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 04-22-2007, 05:06 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1