PC Review


Reply
Thread Tools Rate Thread

Do loop or For Next with data from cells

 
 
MovingBeyondtheRecordButton
Guest
Posts: n/a
 
      23rd Mar 2010
I have seen many examples on how to give cells values but I want to use the
value that is in a certain cell. I have a list of submission numbers that
are contained in two columns of data in Sheet 1 Cells A4:A40 and F4:F40. I
have a currently working macro that has an Application.InputBox where the
user types a submission number and a sql query is excuted for that submission
number. The information from the sql query gets placed in Sheet 3. I want to
excute this sql query for each of the submission numbers. So I need to
change the code that reads

mynum = Application.InputBox("Select Submission_ID")

to use each of the submissions contained in Cells A4:A40 and F4:F40.

Each time this sql query runs I want to use the countif fuction on some of
the data that returns from the query. Here the countif fuctions I am using.

=SUMPRODUCT((Sheet3!$F$2:$F$401<>"")/COUNTIF(Sheet3!$F$2:$F$401,Sheet3!$F$2:$F$401&"")

=COUNTIF(Sheet3!$G$2:$G$401,"INCOMPLETE")

These fuctions work...I need to Copy and paste the values only uptained from
these fuctions into certain cells in Sheet 2. I know I will need to use a
Paste Special (values only) because if I leave the formula in the sheet and
use the regular copy paste then the formula gets copied too. Then each time
the sql query runs the information I looked up about previous submission gets
changed to the information about the current submission.
Then I need the macro to loop and query the next submission.

In Summary:

Do Sql Query for mySubmission
Use count fuction on data from query
Paste (values only) from count fuction
Loop 'needs to loop for each submission in A4:A40 then F4:F40

Thanks in advance for any guidance you can give.
Note: Submission numbers are too large to be called an interger.
 
Reply With Quote
 
 
 
 
MovingBeyondtheRecordButton
Guest
Posts: n/a
 
      23rd Mar 2010
Here is the Code for the Sql Query Macro:

Sub VIEW_TASK_DETAIL()
Dim i As Integer

Sheets("Sheet1").Select
mynum = Application.InputBox("Select Submission_ID")
Num = 1000 & mynum

Sheets("Sheet3").Select
Columns("A:O").Select
Selection.ClearContents
Range("A1").Select


With ActiveSheet.QueryTables.Add(Connection:= _

"ODBC;DSN=OurDNS;UID=TheUsersName;PWD=TheUsersPassword;SERVER=NameofServer;",
Destination:=Sheets _
("Sheet3").Range("A1"))
.CommandText = Array( Array contents)

.Name = "Query from OurDNS"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = True
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=False
End With
Range("A1").Select
End Sub


"MovingBeyondtheRecordButton" wrote:

> I have seen many examples on how to give cells values but I want to use the
> value that is in a certain cell. I have a list of submission numbers that
> are contained in two columns of data in Sheet 1 Cells A4:A40 and F4:F40. I
> have a currently working macro that has an Application.InputBox where the
> user types a submission number and a sql query is excuted for that submission
> number. The information from the sql query gets placed in Sheet 3. I want to
> excute this sql query for each of the submission numbers. So I need to
> change the code that reads
>
> mynum = Application.InputBox("Select Submission_ID")
>
> to use each of the submissions contained in Cells A4:A40 and F4:F40.
>
> Each time this sql query runs I want to use the countif fuction on some of
> the data that returns from the query. Here the countif fuctions I am using.
>
> =SUMPRODUCT((Sheet3!$F$2:$F$401<>"")/COUNTIF(Sheet3!$F$2:$F$401,Sheet3!$F$2:$F$401&"")
>
> =COUNTIF(Sheet3!$G$2:$G$401,"INCOMPLETE")
>
> These fuctions work...I need to Copy and paste the values only uptained from
> these fuctions into certain cells in Sheet 2. I know I will need to use a
> Paste Special (values only) because if I leave the formula in the sheet and
> use the regular copy paste then the formula gets copied too. Then each time
> the sql query runs the information I looked up about previous submission gets
> changed to the information about the current submission.
> Then I need the macro to loop and query the next submission.
>
> In Summary:
>
> Do Sql Query for mySubmission
> Use count fuction on data from query
> Paste (values only) from count fuction
> Loop 'needs to loop for each submission in A4:A40 then F4:F40
>
> Thanks in advance for any guidance you can give.
> Note: Submission numbers are too large to be called an interger.

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert Data Last Row Loop through cells Excel 2000 & 2003 jfcby Microsoft Excel Programming 5 15th Dec 2006 05:28 PM
Help - loop through cells in a range that are not together (several different cells as Target) Marie J-son Microsoft Excel Programming 4 3rd Apr 2005 09:54 PM
Loop cells - get all rows with matching data - paste into different wb Buffyslay_co_uk Microsoft Excel Programming 2 23rd Jul 2004 01:20 PM
Loop through cells Sheeny Microsoft Excel Programming 7 6th May 2004 12:02 AM
VBA loop cells Adrie Rahanra Microsoft Excel Programming 1 30th Sep 2003 10:22 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:39 AM.