473,386 Members | 1,630 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,386 software developers and data experts.

I need a macro to delete rows in various worksheets

I have an Excel workbook, which is an order form using tick boxes, if "ticked"(true)the item seleted data appears into other worksheets. If it returns "" (blank)then I want to delete the blank rows in various other worksheets within the workbook.

Can someone please help with some code I have the following code which will work in 1 worksheet but i can not get it to do the same in the other worksheets

Expand|Select|Wrap|Line Numbers
  1. Sub Deleterow()
  2. Dim rngstart As Range
  3. Dim rngend As Range
  4. Dim n As Integer
  5.  
  6. 'set start of data column "A"
  7.  
  8. Set rngstart = Range("a1")
  9.  
  10. 'set end of data column "A"
  11.  
  12. Set rngend = Range("a10")
  13.  
  14. 'working from bottom totop
  15.  
  16. For n = rngend.Row To rngstart.Row Step -1
  17.  
  18. 'test valve in column A
  19.  
  20. If Range("A" & CStr(n)).Value = False Then
  21.  
  22. 'match words and delete
  23.  
  24. Range("A" & CStr(n)).EntireRow.Delete
  25.  
  26. End If
  27.  
  28. Next n
  29.  
  30. End Sub
Feb 23 '11 #1

✓ answered by Guido Geurs

You have to go to each sheet like:
Expand|Select|Wrap|Line Numbers
  1. Sub Deleterow()
  2. Dim rngstart As Range
  3. Dim rngend As Range
  4. Dim n As Integer
  5. Dim SHEETidx As Integer
  6.    For SHEETidx = 1 To Sheets.Count
  7.       Sheets(SHEETidx).Activate
  8.       'set start of data column "A"
  9.       Set rngstart = Range("a1")
  10.       'set end of data column "A"
  11.       Set rngend = Range("a10")
  12.       'working from bottom totop
  13.       For n = rngend.Row To rngstart.Row Step -1
  14.          'test valve in column A
  15.          If Range("A" & CStr(n)).Value = False Then
  16.             'match words and delete
  17.             Range("A" & CStr(n)).EntireRow.Delete
  18.          End If
  19.       Next n
  20.    Next SHEETidx
  21. End Sub

2 1918
Guido Geurs
767 Expert 512MB
You have to go to each sheet like:
Expand|Select|Wrap|Line Numbers
  1. Sub Deleterow()
  2. Dim rngstart As Range
  3. Dim rngend As Range
  4. Dim n As Integer
  5. Dim SHEETidx As Integer
  6.    For SHEETidx = 1 To Sheets.Count
  7.       Sheets(SHEETidx).Activate
  8.       'set start of data column "A"
  9.       Set rngstart = Range("a1")
  10.       'set end of data column "A"
  11.       Set rngend = Range("a10")
  12.       'working from bottom totop
  13.       For n = rngend.Row To rngstart.Row Step -1
  14.          'test valve in column A
  15.          If Range("A" & CStr(n)).Value = False Then
  16.             'match words and delete
  17.             Range("A" & CStr(n)).EntireRow.Delete
  18.          End If
  19.       Next n
  20.    Next SHEETidx
  21. End Sub
Feb 25 '11 #2
Thank you Guido, it does just what i wanted.
Many thanks
Mar 3 '11 #3

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

Similar topics

2
by: rcamarda | last post by:
Hi, I need to delete rows from my user tables dependant upon there non existence from another table: delete student where student_id not in (select student_id from tblStudent) The reasons is...
11
by: suma | last post by:
Hello, I want to delete duplicate rows in a table when no primary key is defined. For eg: If we have table1 with data as below, Suma 23 100 Suma 23 100 I want to delete a row from this...
1
by: mr_ocp | last post by:
Hi friends I need routines to create an excel file with worksheets for each customer and a text file as well for each customer, first worksheet would be a "Summary Report", here is the code that...
2
by: avanti | last post by:
Hi, I am trying to delete rows from a TableLayoutPanel at Runtime. I tried editing the RowStyles collection but doesn't do what I want it to. I have a table with 10 rows. I want to delete rows 2...
0
by: hafeez | last post by:
Hi, I have two mssql databases. I am able to create a linked server. I want to delete some of the rows using this linked server. Here HAFEEZ is one mssql database and DPVSQSL is another.So, i...
1
by: madhavi123 | last post by:
Hi All, I have tables in three hierarchy... I need to delete rows from the table which in 3rd level of hierarchy. For ex: Table 1 has primary key col1. Table 2 has primary key...
1
vikysaran
by: vikysaran | last post by:
Hi, i want to delete rows from two tables using one sql statement. One table is tblEmployee and other is tblUser and i want to delete all record in both of table whose UserID is EE00001
1
by: abdulkarim | last post by:
I have tried to delete rows in a table with same ID in access database by using the following vb code with a click on command button, but it deletes only a single row instead of entire rows with same...
3
by: lisles | last post by:
hey,i've got a page that displays rows from a db.im want a function to dynamically delete rows.i've put it 1,bt i get an error as follows: Parse error: syntax error, unexpected T_STRING, expecting...
0
by: aswaditya | last post by:
Hi, I am new to SSIS packages. I have 6 Excel workbooks with data spread over two worksheets each and i have to map individual data to individual SQL tables. Please note that each worksheet is...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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.