473,386 Members | 1,798 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.

Having some trouble using increments in While...Wend loop

5
hi,

I'm having trouble incrementing inside a While...Wend loop.

i = 0

While <condition>

<statement>
i = i + 2
<statement>

Wend

I am able to execute my While statement properly but I am only able to do the first increment of i with this piece of code and then it stops after. Any help would be much appreciated. Thanks.
Sep 5 '13 #1
8 1218
Rabbit
12,516 Expert Mod 8TB
That depends on what the condition is.
Sep 5 '13 #2
hdman
5
Here is my code. I am copying data from one spreadsheet to a new spreadsheet (the code is run from the new spreadsheet). I am trying to format the text in the new spreadsheet so that there is some space between tables and so that the column header text is wrapped. I am trying to increment i to do the formatting but it only seems to work the first time:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Sub findRanges()
  3.  
  4.     On Error Resume Next
  5.  
  6.     Dim Wb1 As Workbook, wb2 As Workbook
  7.     Dim startRow As Long
  8.     Dim endRow As Long
  9.     Dim i As Integer
  10.     LookupString = "Unique Well ID"
  11.  
  12.  
  13.     'copy from workbook 2'
  14.     Set wb2 = Workbooks.Open("C:\Users\hdhingra\Desktop\Example\EX.xlsx")
  15.  
  16.     'To This
  17.     Set Wb1 = ThisWorkbook
  18.  
  19.     startRow = 1
  20.     endRow = wb2.Sheets(1).Range("A1").EntireColumn.find(What:=LookupString, After:=Range("A1"), LookIn:=xlFormulas, _
  21.         LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
  22.         MatchCase:=False, SearchFormat:=False).Row - 1
  23.  
  24.     'paste production data of first well to template***
  25.  
  26.     wb2.Sheets(1).Range("A" & startRow & ":H" & endRow).Copy Wb1.Sheets(1).Range("C4" & ":J" & endRow + 3)
  27.     Wb1.Sheets(1).Range("C6:J6").WrapText = True
  28.  
  29.     '*************************************************************************************************************************************
  30.     startRow = endRow + 1
  31.     i = 0
  32.  
  33.     While wb2.Sheets(1).Range("A" & startRow).value <> "" And i <> "20"
  34.  
  35.     endRow = wb2.Range("A" & startRow).EntireColumn.find(What:=LookupString, After:=Range("A" & startRow), LookIn:=xlFormulas, _
  36.         LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
  37.         MatchCase:=False, SearchFormat:=False).Row - 1
  38.  
  39.     'Range("K2") = endRow
  40.     'Range("K3") = startRow
  41.     'Range("K4") = wb2.Sheets(1).Range("A1").End(xlDown).Row
  42.  
  43.         'find last row of data
  44.         If Err.Number <> 0 Then
  45.             endRow = wb2.Sheets(1).Range("A1").End(xlDown).Row
  46.         End If
  47.  
  48.     i = i + 2
  49.     wb2.Sheets(1).Range("A" & startRow & ":H" & endRow).Copy Wb1.Sheets(1).Range("C" & startRow + 3 + i & ":J" & endRow + 3 + i)
  50.     Wb1.Sheets(1).Range("A" & startRow + 5 + i & ":J" & startRow + 5 + i).WrapText = True
  51.  
  52.     startRow = endRow + 1
  53.  
  54.     Wend
  55.  
  56.  
Thanks.
Sep 5 '13 #3
hdman
5
There is also an End Sub at the end, sorry....
Sep 5 '13 #4
Rabbit
12,516 Expert Mod 8TB
I'm surprised it runs even once. On line 30 you set the start to be equal to the row after the last. It should never even loop since you're checking to see if the row after the last row has any data, which it never should.
Sep 5 '13 #5
hdman
5
Actually, with reference to the spreadsheet that I am copying data from; the point where I check to see when I have reached the last row of data is line 45.

in line 30, i defined the variables startRow and endRow. the spreadsheet that i am copying from actually has several tables (same number of columns and rows).

I use the LookupString variable to help identify the row number at which a new table begins. Thats what I use to define startRow = endRow + 1.

Still stuck :(
Sep 5 '13 #6
Rabbit
12,516 Expert Mod 8TB
It would have helped to know that earlier. The problem is line 35, there is no range property on a workbook. Compare that line to line 20.
Sep 5 '13 #7
hdman
5
That's it, Thanks a bunch!!!!!!
Sep 5 '13 #8
Rabbit
12,516 Expert Mod 8TB
No problem, good luck on the rest of your project.
Sep 6 '13 #9

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

Similar topics

1
by: moondaddy | last post by:
I'm running vb.net 1.1 and I need to register a dll using regsvcs.exe and am getting the error: Command "RegSvcs.exe" is not valid. the path to the dll I want to register is: D:\nwis\Apps\CSLA...
0
by: Eric | last post by:
Hi, I've been trying in vain to get the number of copies a user wants to print after they've closed the PrintDialog form. Apparantly this value is sometimes found in the DEVMODE struct for the...
0
by: RML | last post by:
Hi, I have created a Windows Service which when started, retrieves a file from an FTP server (running W2K Server) via an FTP call. The service is "dependant" on the lanmanworkstation service,...
5
by: tkondal | last post by:
Hi all. I just started looking at Python's ctypes lib and I am having trouble using it for a function. For starters, here's my Python code: from ctypes import*; myStringDLL=...
2
Ajm113
by: Ajm113 | last post by:
Ok, I want to disable any html tags, but the problem is when I do add in the nl2br function with a htmlentities it displays the tags for the <br>! I even keep seeing rn every time I enter a return in...
15
Ajm113
by: Ajm113 | last post by:
Ok I got my stuff to split, but how can I have the while work correctly so it will show all of the arrays correctly? Like if you where using Mysql to retrieve data. But this time it is retrieving all...
10
by: Jason (Kusanagihk) | last post by:
To all, I have written a SerialPort class / application using C# and .Net Framework 3.0. but I have a question; since my serialPort class / application is not a Windows Form application (rather...
2
by: cmb3587 | last post by:
I am having a problem with the validation of the account number and password. The beginning of the program asks for users account # then pwd. The program is then supposed to go to a checkID...
3
sweetzhay
by: sweetzhay | last post by:
i already know how to get the output of 1 12 123 1234 12345 using while wend and now my problem is to show the output of 1 21
5
sweetzhay
by: sweetzhay | last post by:
this code i will have an output of 1 12 123 1234 12345 when pressing command 1 Private Sub Command1_Click() Label1.Caption = Clear
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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,...

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.