Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
most xlent
 
Posts: n/a
Default How to set variable to cell value in excel macro

How do I perform a "do loop" using a cell value as criteria? (i.e.-do while
x < value($c$1). Thanks for your help.
  #2   Report Post  
Don Guillett
 
Posts: n/a
Default How to set variable to cell value in excel macro

the help files are your friend
While...Wend Statement Example
This example uses the While...Wend statement to increment a counter
variable. The statements in the loop are executed as long as the condition
evaluates to True.

Dim Counter
Counter = 0 ' Initialize variable.
While Counter < 20 ' Test value of Counter.
Counter = Counter + 1 ' Increment Counter.
Wend ' End While loop when Counter 19.
Debug.Print Counter ' Prints 20 in the Immediate window.

--
Don Guillett
SalesAid Software

"most xlent" wrote in message
...
How do I perform a "do loop" using a cell value as criteria? (i.e.-do

while
x < value($c$1). Thanks for your help.



  #3   Report Post  
most xlent
 
Posts: n/a
Default How to set variable to cell value in excel macro

Hi Don,
This would work if the cell value was constant, however, it is a result of a
formula that changes with variable input in the worksheet. Currently, I
input data into the worksheet and must look at the value of the cell. Then I
need to edit the macro with the new cell value for the do loop. This becomes
time consuming with all the data I am processing. Ideally, I would like the
macro to retrieve the cell value automatically. Thanks in advance for your
next response.

"Don Guillett" wrote:

the help files are your friend
While...Wend Statement Example
This example uses the While...Wend statement to increment a counter
variable. The statements in the loop are executed as long as the condition
evaluates to True.

Dim Counter
Counter = 0 ' Initialize variable.
While Counter < 20 ' Test value of Counter.
Counter = Counter + 1 ' Increment Counter.
Wend ' End While loop when Counter 19.
Debug.Print Counter ' Prints 20 in the Immediate window.

--
Don Guillett
SalesAid Software

"most xlent" wrote in message
...
How do I perform a "do loop" using a cell value as criteria? (i.e.-do

while
x < value($c$1). Thanks for your help.




  #5   Report Post  
Kleev
 
Posts: n/a
Default How to set variable to cell value in excel macro

You could do something like this:
Dim ws As Worksheet
Dim i As Integer
Dim x As Integer
Set ws = ThisWorkbook.Worksheets("sheet2")
i = ws.Range("c1").Value
x = 1
Do While x < i
ws.Cells(x, 4).Value = x + i
x = x + 1
Loop

"most xlent" wrote:

How do I perform a "do loop" using a cell value as criteria? (i.e.-do while
x < value($c$1). Thanks for your help.



  #6   Report Post  
most xlent
 
Posts: n/a
Default How to set variable to cell value in excel macro

Way to go Kleev!
Your suggestion did the trick. Thanks alot!

"Kleev" wrote:

You could do something like this:
Dim ws As Worksheet
Dim i As Integer
Dim x As Integer
Set ws = ThisWorkbook.Worksheets("sheet2")
i = ws.Range("c1").Value
x = 1
Do While x < i
ws.Cells(x, 4).Value = x + i
x = x + 1
Loop

"most xlent" wrote:

How do I perform a "do loop" using a cell value as criteria? (i.e.-do while
x < value($c$1). Thanks for your help.

  #7   Report Post  
Kleev
 
Posts: n/a
Default How to set variable to cell value in excel macro

You are welcome.

"most xlent" wrote:

Way to go Kleev!
Your suggestion did the trick. Thanks alot!

"Kleev" wrote:

You could do something like this:
Dim ws As Worksheet
Dim i As Integer
Dim x As Integer
Set ws = ThisWorkbook.Worksheets("sheet2")
i = ws.Range("c1").Value
x = 1
Do While x < i
ws.Cells(x, 4).Value = x + i
x = x + 1
Loop

"most xlent" wrote:

How do I perform a "do loop" using a cell value as criteria? (i.e.-do while
x < value($c$1). Thanks for your help.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Urgent Help Required on Excel Macro Problem Sachin Shah Excel Discussion (Misc queries) 1 August 17th 05 06:26 AM
How do I set a macro to print variable number of pages in excel? Livio Excel Discussion (Misc queries) 1 July 30th 05 12:15 AM
How can I edit cell contents with a macro in Excel? Mind the gaps! Excel Discussion (Misc queries) 2 March 23rd 05 08:51 PM
How can I edit cell contents with a macro in Excel? NotAnExpert Excel Discussion (Misc queries) 1 March 23rd 05 01:17 AM
How to save Excel macro using name contained in cell? CG Excel Worksheet Functions 1 February 3rd 05 03:51 PM


All times are GMT +1. The time now is 04:07 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"