Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Query & Write

Datasheet contains
Row 1( Header)---- Date Na Nb Nc Nd
Row 2 31/10/03 1 8 3 4
Row 3 01/11/03 5 8 2 9

Querysheet contains
Row 1(Header)---- Date Rowno 1 3 5 6 9
Row 2 31/10/03 2 0 0 1 0 1

Query conditions a
Look in the datasheet at row2 for a value of 1, if found, then look at
next row i.e. row3 for value found in the querysheet in this case are
1,3,5,6,9 . If found, it will write the date & rowno of row2 of
datasheet and the value of 1 & 0 will be insert accordingly to the
column.
This macro will run the loops from row2 of datasheet until the last
row.
Thank you for helping.



------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from http://www.ExcelForum.com/

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 599
Default Query & Write

Michael

Try this

Sub QrySheet()

Dim DSh As Worksheet
Dim QSh As Worksheet
Dim i As Long, k As Long
Dim cell As Range
Dim Rng As Range
Dim MtchFnd As Variant

With ThisWorkbook
Set DSh = .Worksheets("Datasheet")
Set QSh = .Worksheets("Querysheet")
End With

Set Rng = DSh.Range("a2", DSh.Range("A65536").End(xlUp))
k = 1

For Each cell In Rng
If InStr("," & cell.Offset(0, 1).Value & _
"," & cell.Offset(0, 2).Value & _
"," & cell.Offset(0, 3).Value & _
"," & cell.Offset(0, 4).Value & ",", ",1,") 0 Then

k = k + 1
QSh.Cells(k, 1).Value = cell.Value
QSh.Cells(k, 2).Value = cell.Row
QSh.Range("C" & k & ":G" & k).Value = 0

For i = 1 To 4
MtchFnd = Application.Match(cell.Offset(1, i).Value, _
QSh.Range("c1:G1"), False)

If Not IsError(MtchFnd) Then
QSh.Range("b" & k).Offset(0, MtchFnd).Value = 1
End If
Next i
End If
Next cell

End Sub

--
Dick Kusleika
MVP - Excel
www.dicks-clicks.com
Post all replies to the newsgroup.

"Michael168" wrote in message
...
Datasheet contains
Row 1( Header)---- Date Na Nb Nc Nd
Row 2 31/10/03 1 8 3 4
Row 3 01/11/03 5 8 2 9

Querysheet contains
Row 1(Header)---- Date Rowno 1 3 5 6 9
Row 2 31/10/03 2 0 0 1 0 1

Query conditions a
Look in the datasheet at row2 for a value of 1, if found, then look at
next row i.e. row3 for value found in the querysheet in this case are
1,3,5,6,9 . If found, it will write the date & rowno of row2 of
datasheet and the value of 1 & 0 will be insert accordingly to the
column.
This macro will run the loops from row2 of datasheet until the last
row.
Thank you for helping.



------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from http://www.ExcelForum.com/



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
Excel 2007 / MS Query - editing existing query to another sheet Hotpepperz Excel Discussion (Misc queries) 0 June 13th 08 06:53 PM
How to write parameter query with "or is null" criteria Vincent Alliance New Users to Excel 0 April 8th 06 02:55 AM
write a query to retrieve data query New Users to Excel 1 March 17th 06 06:01 PM
is it possible to execute write to the fields in another .xsl form a macro in another .xsl? e.g. some way to load another .xsl into an .xsl macro and write to its data? Daniel Excel Worksheet Functions 1 June 23rd 05 11:38 PM
query will not write to excel Klutzz Excel Discussion (Misc queries) 0 March 26th 05 01:37 PM


All times are GMT +1. The time now is 06:40 AM.

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

About Us

"It's about Microsoft Excel"