473,398 Members | 2,088 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,398 software developers and data experts.

Insert blank row problem Excel 2000

63
I am trying to write some code to get Excel 2000 to insert a blank row wherever there is a "NO" in column O (above the NO). The code below nearly does this - but not quite!. The problem I have is that if there are 2 or 3 consecutive NO's in column O then this code inserts 2 or 3 rows above the first "NO" and doesn't insert a row inbetween each "NO"

NB the data range will change - so I will have to use some sort of search function to locate where the NO's are in the range.


any ideas on how to get excel to insert a row above each "NO"?

thanks


Dim MyRangenew As Range, DelRangenew As Range, Fnew As Range
Dim MatchStringnew As String, SearchColumnnew As String, ActiveColumnnew As String
Dim FirstAddressnew As String, NullChecknew As String
Dim AFnew

Set MyRangenew = Columns("O")

Set Fnew = MyRangenew.Find(What:="NO", after:=MyRangenew.Cells(1), LookIn:=xlValues, Lookat:=xlPart)
If Not Fnew Is Nothing Then
Set DelRangenew = Fnew
FirstAddressnew = Fnew.Address
Do
Set Fnew = MyRangenew.FindNext(Fnew)
Set DelRangenew = Union(DelRangenew, Fnew)
Loop While FirstAddressnew <> Fnew.Address
End If

'If there are valid matches then delete the rows
If Not DelRangenew Is Nothing Then DelRangenew.EntireRow.Insert Shift:=xlDown

Application.ScreenUpdating = True
Sep 3 '07 #1
6 1981
QVeen72
1,445 Expert 1GB
Hi,

This works fine here :

Expand|Select|Wrap|Line Numbers
  1. Dim MyRangenew As Range, DelRangenew As Range, Fnew As Range
  2. Dim MatchStringnew As String, SearchColumnnew As String, ActiveColumnnew As String
  3. Dim FirstAddressnew As String, NullChecknew As String
  4. Dim K
  5. Dim T
  6. Set MyRangenew = Columns("O")
  7. K = 1
  8. Set Fnew = MyRangenew.Find(What:="NO", after:=MyRangenew.Cells(K), LookIn:=xlValues, Lookat:=xlPart)
  9. If Not Fnew Is Nothing Then T = Fnew.Row
  10. Do
  11.    Set Fnew = MyRangenew.Find(What:="NO", after:=MyRangenew.Cells(K), LookIn:=xlValues, Lookat:=xlPart)
  12.    If Not Fnew Is Nothing Then
  13.       Set DelRangenew = Fnew
  14.       K = Fnew.Row + 1
  15.       If K = (T + 2) Then Exit Do
  16.       If Not DelRangenew Is Nothing Then
  17.          DelRangenew.EntireRow.Insert Shift:=xlDown
  18.       End If
  19.    Else
  20.      Exit Do
  21.    End If
  22. Loop Until K <= T
  23.  
  24. Application.ScreenUpdating = True
  25.  
REgards
Veena
Sep 3 '07 #2
grego9
63
Veena - thanks for the help - When I type this code in I get the following message " Compile Error Else Without IF" and the Else word is highlighted

any ideas?

thanks again



Hi,

This works fine here :

Expand|Select|Wrap|Line Numbers
  1. Dim MyRangenew As Range, DelRangenew As Range, Fnew As Range
  2. Dim MatchStringnew As String, SearchColumnnew As String, ActiveColumnnew As String
  3. Dim FirstAddressnew As String, NullChecknew As String
  4. Dim K
  5. Dim T
  6. Set MyRangenew = Columns("O")
  7. K = 1
  8. Set Fnew = MyRangenew.Find(What:="NO", after:=MyRangenew.Cells(K), LookIn:=xlValues, Lookat:=xlPart)
  9. If Not Fnew Is Nothing Then T = Fnew.Row
  10. Do
  11.    Set Fnew = MyRangenew.Find(What:="NO", after:=MyRangenew.Cells(K), LookIn:=xlValues, Lookat:=xlPart)
  12.    If Not Fnew Is Nothing Then
  13.       Set DelRangenew = Fnew
  14.       K = Fnew.Row + 1
  15.       If K = (T + 2) Then Exit Do
  16.       If Not DelRangenew Is Nothing Then
  17.          DelRangenew.EntireRow.Insert Shift:=xlDown
  18.       End If
  19.    Else
  20.      Exit Do
  21.    End If
  22. Loop Until K <= T
  23.  
  24. Application.ScreenUpdating = True
  25.  
REgards
Veena
Sep 4 '07 #3
QVeen72
1,445 Expert 1GB
Hi,

That Code works fine here.. Can u post ur Code here after modification..? MAy be while doing Copy /Paste, Some things might have missed....

Regards
Veena
Sep 4 '07 #4
grego9
63
Veena - here is the code - I've scanned through it and can't find any differences - apologies if I have missed something!

thanks for your help

Dim MyRangenew As Range, DelRangenew As Range, Fnew As Range
Dim MatchStringnew As String, SearchColumnnew As String, ActiveColumnnew As String
Dim FirstAddressnew As String, NullChecknew As String
Dim K
Dim T



Set MyRangenew = Columns("O")
K = 1

Set Fnew = MyRangenew.Find(What:="NO", after:=MyRangenew.Cells(K), LookIn:=xlValues, Lookat:=xlPart)
If Not Fnew Is Nothing Then T = Fnew.Row
Do
Set Fnew = MyRangenew.Find(What:="NO", after:=MyRangenew.Cells(K), LookIn:=xlValues, Lookat:=xlPart)
If Not Fnew Is Nothing Then
Set DelRangenew = Fnew
K = Fnew.Row + 1
If K = (T + 2) Then Exit Do
If Not DelRangenew Is Nothing Then DelRangenew.EntireRow.Insert Shift:=xlDown
End If
Else
Exit Do
End If
Loop Until K <= T

Application.ScreenUpdating = True

Hi,

That Code works fine here.. Can u post ur Code here after modification..? MAy be while doing Copy /Paste, Some things might have missed....

Regards
Veena
Sep 4 '07 #5
QVeen72
1,445 Expert 1GB
Hi,

Line Breaks here :

Expand|Select|Wrap|Line Numbers
  1.         If Not DelRangenew Is Nothing Then 
  2.               DelRangenew.EntireRow.Insert Shift:=xlDown
  3.         End If
  4.  
Posting the Entire Code Again for ur Reference (with proper Indentation):

Expand|Select|Wrap|Line Numbers
  1. Dim MyRangenew As Range, DelRangenew As Range, Fnew As Range
  2. Dim MatchStringnew As String, SearchColumnnew As String, ActiveColumnnew As String
  3. Dim FirstAddressnew As String, NullChecknew As String
  4. Dim K
  5. Dim T
  6. Set MyRangenew = Columns("A")
  7. K = 1
  8. Set Fnew = MyRangenew.Find(What:="NO", after:=MyRangenew.Cells(K), LookIn:=xlValues, Lookat:=xlPart)
  9. If Not Fnew Is Nothing Then T = Fnew.Row
  10. Do
  11.     Set Fnew = MyRangenew.Find(What:="NO", after:=MyRangenew.Cells(K), LookIn:=xlValues, Lookat:=xlPart)
  12.     If Not Fnew Is Nothing Then
  13.         Set DelRangenew = Fnew
  14.         K = Fnew.Row + 1
  15.         If K = (T + 2) Then Exit Do
  16.         If Not DelRangenew Is Nothing Then
  17.              DelRangenew.EntireRow.Insert Shift:=xlDown
  18.         End If
  19.     Else
  20.         Exit Do
  21.     End If
  22. Loop Until K <= T
  23. Application.ScreenUpdating = True
  24.  

Regards
Veena
Sep 4 '07 #6
grego9
63
Thanks Veena - it worked perfectly - I've spent hours on this and was losing the will to live - so thank you very much for your help
Sep 4 '07 #7

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

Similar topics

3
by: Dean Bortell | last post by:
This code runs fine on win xp and office xp: string sheetPassword = "Senior1993"; string sheetToOpen = "NewRpt1c.xls"; Excel.Application excelApp = new Excel.Application();...
4
by: brent.ryan | last post by:
How do I get the next int value for a column before I do an insert in MY SQL Server 2000? I'm currently using Oracle sequence and doing something like: select seq.nextval from dual; Then I...
5
by: Bob | last post by:
Hi, I am using Access 2000 to print out an address book. I have designed the report based on a database whose first record is not blank. In the design there is a one line report header, a onle...
0
by: Weyhooi | last post by:
Help ! please help! i can't find the way to insert a new blank row into excel worksheet using C#. Example macro in vb6 as below : Rows("15:15").Select Selection.Insert Shift:=xlDown i have...
17
by: Mansi | last post by:
I need to do some research on how to use excel automation from c#. Does anyone know of any good books related to this subject? Thanks. Mansi
0
by: grego9 | last post by:
I am trying to insert a new blank row above any row in my excel spreadsheet that has the text "NO" in column O. The macro I have written (below) works fine - apart from when there are two or three...
2
by: cbadchris | last post by:
I am writing an import function with asp, and excel that writes imported excel sheets to to several SQL tables and everything works fine until it reaches the "add data for search" section or query 2....
1
by: cb38 | last post by:
I have an Excel spreadsheet where all data resides in column A. Cell A1 is blank and the data follows after that. I need to insert a line after each line with the ChangeType: add. How can I do...
1
by: pexp | last post by:
Hello All, I would like to insert/update a database table using excel file. I have a list of products in an excel file. If product exist in a database table tblproduct than it should update the...
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
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.