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
5 1640
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
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
Not sure whether it might take too long to run, but you try something like this... - Dim C As Range
-
For Each C In Range("A:A")
-
' This loop will execute for each cell in column A...
-
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.
Hi
I think this should do it - Sub RemoveData()
-
Dim i As Long
-
Dim iLastRow As Long
-
Dim iCheckCol As Integer
-
-
iCheckCol = 5 'COLUMN BEING CHECKED
-
iLastRow = ActiveCell.SpecialCells(xlLastCell).Row
-
iLastRow = iLastRow - 1
-
-
For i = iLastRow To 2 Step -1
-
If Not IsNumeric(Cells(i, iCheckCol)) Or Cells(i, iCheckCol) = "" Then
-
Rows(i).Delete
-
End If
-
Next i
-
End Sub
Note this deletes from the bottom, but not Row 1(?).
MTB
... 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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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
|
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...
|
by: Rebecca |
last post by:
could someone tell me the correct syntax for using vlookup
in visual basic
|
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...
|
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...
|
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...
|
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...
|
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!
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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...
|
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...
| |