473,395 Members | 1,437 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

visual basic for excel

vb code question. i am trying to understand how to get a macro using vb to:
if i have a column of numbers, go through the whole column and identify any number that is less than say 10,000 and then select the entire row that number is on and delete the entire row. continue the process through the entire column. also, some cells in the column will be blank (delete), words (delete), and symbols such as # (delete).

i'm a relative novice here so any help would be appreciated.

Thanks,
MDC
Jul 25 '07 #1
5 1640
MikeTheBike
639 Expert 512MB
vb code question. i am trying to understand how to get a macro using vb to:
if i have a column of numbers, go through the whole column and identify any number that is less than say 10,000 and then select the entire row that number is on and delete the entire row. continue the process through the entire column. also, some cells in the column will be blank (delete), words (delete), and symbols such as # (delete).

i'm a relative novice here so any help would be appreciated.

Thanks,
MDC
Yes it can be done but one question, if some cells can be blank, how do we know where the data ends?

MTB
Jul 25 '07 #2
Well, the data will vary day to day. I think, however, it will never go beyond 5,000 rows. So maybe the macro should go to A5000 then stop?

Thanks for the help.

Matthew
Jul 25 '07 #3
Killer42
8,435 Expert 8TB
Not sure whether it might take too long to run, but you try something like this...
Expand|Select|Wrap|Line Numbers
  1. Dim C As Range
  2. For Each C In Range("A:A")
  3.   ' This loop will execute for each cell in column A...
  4. Next
I've forgotten for the moment how to check whether they're numeric/null/etc and delete the rows. Plus, I've just typed this here without testing it. But the logic may help get you started.
Jul 26 '07 #4
MikeTheBike
639 Expert 512MB
Hi

I think this should do it

Expand|Select|Wrap|Line Numbers
  1. Sub RemoveData()
  2.     Dim i As Long
  3.     Dim iLastRow As Long
  4.     Dim iCheckCol As Integer
  5.  
  6.     iCheckCol = 5 'COLUMN BEING CHECKED
  7.     iLastRow = ActiveCell.SpecialCells(xlLastCell).Row
  8.     iLastRow = iLastRow - 1
  9.  
  10.     For i = iLastRow To 2 Step -1
  11.         If Not IsNumeric(Cells(i, iCheckCol)) Or Cells(i, iCheckCol) = "" Then
  12.             Rows(i).Delete
  13.         End If
  14.     Next i
  15. End Sub
Note this deletes from the bottom, but not Row 1(?).


MTB
Jul 26 '07 #5
Killer42
8,435 Expert 8TB
... Note this deletes from the bottom, but not Row 1(?).
Thanks Mike. That's an important point which is often overlooked (and accounts for a number of enquiries that have been made here in the past).

If you start from the top, of course, then each time you delete one, you may miss the following one.
Jul 27 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: JW | last post by:
I am looking for sample code to learn me about using excel from a visual basic program. I want to open a file, store code in a certain cell and save this again. Who can help me Regards
3
by: Omar | last post by:
Hi Developers, I am trying to access an Excel data file through a VB.Net application. I have the following code: =================================== VB.Net Code =================== Dim...
2
by: Rebecca | last post by:
could someone tell me the correct syntax for using vlookup in visual basic
5
by: JimS | last post by:
I just got myself a Visual Basic.Net compiler, and I'm looking for books to help me learn. Specifically, I'm a very experienced programmer (going back to 1968), I'm pretty accomplished in VBA for...
10
by: Steve | last post by:
I am trying to create a DLL in Visual Studio 2005-Visual Basic that contains custom functions. I believe I need to use COM interop to allow VBA code in Excel 2002 to access it. I've studied...
1
by: akshaysk | last post by:
HI, I am new to Visual Basic. For my Assignment i am supposed to write a visual basic program using excel. I have tried many scripts, but receive errors. Can anyone tell me of any website that...
4
by: bilalbajwa2336 | last post by:
I want to make a program in visual basic. When i put my salary data in VB (like: Time In , Time Out, DAte, DAy) VB automatically (in the back ground) input this data in the Excel and Show out puts of...
2
by: Vmrincon | last post by:
Hi! I need to crete a visual basic .net application to read Excel 2000 files. Does anyone know if I need some kind of driver or some extra file to be able to do it? Thanks a lot!
1
by: chrspta | last post by:
I am new to Visual basic. I need a program using VB6 that converts txt files to excel file.Description is in the below: The form should have the Drive list, Dir list, file list and cmdConvert...
4
by: bonkbc | last post by:
hi! how can we take textbox data from a visual basic 6.0 form and write it to an excel worksheet once a command button is clicked? I've gotten very close to completing this on my own, here is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.