sunshine737
asked on
getting the data in between the cells dynamically
im retreiving data dynamically from oracle db and the data is displayed something like
1 test
1 test
1 test
so now i want to display someother data in between these data and also group them, something like
1 test
stn nr desc
1 test
stn nr desc
stn nr desc
1 test
stn nr desc
-------------------------- -
rec.Open "SELECT * FROM project_data3 where ang_kost1='" & clk & "'", conn
While Not rec.EOF
i = i + 1
Tabelle2.Cells(i, 1) = (rec.Fields("ver_nr1").Val ue)
Tabelle2.Cells(i, 2) = (rec.Fields("ver_bes1").Va lue)
rec.MoveNext
Wend
1 test
1 test
1 test
so now i want to display someother data in between these data and also group them, something like
1 test
stn nr desc
1 test
stn nr desc
stn nr desc
1 test
stn nr desc
--------------------------
rec.Open "SELECT * FROM project_data3 where ang_kost1='" & clk & "'", conn
While Not rec.EOF
i = i + 1
Tabelle2.Cells(i, 1) = (rec.Fields("ver_nr1").Val
Tabelle2.Cells(i, 2) = (rec.Fields("ver_bes1").Va
rec.MoveNext
Wend
ASKER
how can i group them dynamically and also give them color, i mean to the rows
What do you mean group them? show an example of how you them to display
For the colour select the column you want to color like this
Tabelle2.Cells(i, 1).select
Then color it like this
With Selection.Interior
.ColorIndex = 6
.Pattern = xlSolid
End With
For the colour select the column you want to color like this
Tabelle2.Cells(i, 1).select
Then color it like this
With Selection.Interior
.ColorIndex = 6
.Pattern = xlSolid
End With
ASKER
by grouping i mean doing this control automatically
top menu - Data - group and outline - group
top menu - Data - group and outline - group
ASKER
i = i + 1
Tabelle2.Cells(i, 1) = (rec.Fields("ver_nr1").Val ue)
Tabelle2.Cells(i, 2) = (rec.Fields("ver_bes1").Va lue)
i = i + 1 'this makes room for the values you want to enter
Tabelle2.Cells(i, 1) = (rec.Fields("New_Field_Her e").Value)
Tabelle2.Cells(i, 2) = (rec.Fields("New_Field_Her e").Value)
leaving the above two i want to colour the entire row
Tabelle2.Cells(i, 1) = (rec.Fields("ver_nr1").Val
Tabelle2.Cells(i, 2) = (rec.Fields("ver_bes1").Va
i = i + 1 'this makes room for the values you want to enter
Tabelle2.Cells(i, 1) = (rec.Fields("New_Field_Her
Tabelle2.Cells(i, 2) = (rec.Fields("New_Field_Her
leaving the above two i want to colour the entire row
OK. Here
Range("A23:A33").Select
Selection.Rows.Group
If you don't know where the range ends, the value of variable i after the while loop ends will contain the last row we put data in, so you could do
Range("A23:A" & i).Select
Selection.Rows.Group
Range("A23:A33").Select
Selection.Rows.Group
If you don't know where the range ends, the value of variable i after the while loop ends will contain the last row we put data in, so you could do
Range("A23:A" & i).Select
Selection.Rows.Group
To color entire row
Tabelle2.Cells(i, 1).entirerow.select
With Selection.Interior
.ColorIndex = 6 'This is yellow, what color do you want
.Pattern = xlSolid
End With
Tabelle2.Cells(i, 1).entirerow.select
With Selection.Interior
.ColorIndex = 6 'This is yellow, what color do you want
.Pattern = xlSolid
End With
ASKER
>>>'This is yellow, what color do you want
i want light blue
i want light blue
ASKER
when im selecting a new one its throwing error at this line >>>Selection.Rows.Group
as the group methd of the range object cannot be called
as the group methd of the range object cannot be called
All the blur colors I can see are
8,5,28,42,34,33,32
Try these numbers one at a time to see which one suits you best. Just change ColorIndex
ColorIndex = yournumberhere
8,5,28,42,34,33,32
Try these numbers one at a time to see which one suits you best. Just change ColorIndex
ColorIndex = yournumberhere
ASKER
and also the grouping is remaining, how can i make a new grouping with each selection, and when nothing is selected then no grouping shld be visible
I don't understand this. what do you mean "with each selection". Do you mean the user selects a row, a column or several rows maybe. Explain a bit more. It is not really easy to imagine what you have in mind without verbose explanation
ASKER
oops sorry
well im having two comboboxes, one us having order number and other is having suborder numbers, combining both im taking as a value and retreiving data from a view, so each sub order has different data, so this data i want to display in the format of
ver_nr1 desc
stn_nr details year
stn_nr details year
ver_nr2 desc
stn_nr details year
stn_nr details year
and to these data i want to colour and group data depending on ver_nr
so ver_nr1 will become one group and 2 will become another group
well im having two comboboxes, one us having order number and other is having suborder numbers, combining both im taking as a value and retreiving data from a view, so each sub order has different data, so this data i want to display in the format of
ver_nr1 desc
stn_nr details year
stn_nr details year
ver_nr2 desc
stn_nr details year
stn_nr details year
and to these data i want to colour and group data depending on ver_nr
so ver_nr1 will become one group and 2 will become another group
ASKER
well how can i delete or take out grouping before a new group is made
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
sorry was out for some time
thanks a lot
thanks a lot
ASKER
just one more thing, how can i take out colouring??
with first one some cells are coloured and with the second one, the old one is remaining
i want the cells to be coloured only till the values are there
with first one some cells are coloured and with the second one, the old one is remaining
i want the cells to be coloured only till the values are there
With Selection.Interior
.ColorIndex = xlColorIndexNone
.Pattern = xlSolid
End With
You need to use the help as all this info is in th help file. Make sure you have VBA help installed with Excel (it doesn't install by default) then just highligh a word a press F1. For example if you highlight ColorIndex and press F1 it will tell you the color values
ASKER
>>>> With Selection.Interior
.ColorIndex = xlColorIndexNone
.Pattern = xlSolid
End With
i mean with every selection, old values and old colour shld go away and new values and colour should come
.ColorIndex = xlColorIndexNone
.Pattern = xlSolid
End With
i mean with every selection, old values and old colour shld go away and new values and colour should come
ASKER
i tried using help and also some macros, but they arent so helpful
Can you post what the code look like now and put comment on where you want the colors be removed
ASKER
my code is something like this, but im not able to clear the contents and colour with every new selection, i dont know where im going wrong
Private Sub CommandButton3_Click()
Dim clk As String
Dim i As Integer
clk = ComboBox1.List(ComboBox1.L istIndex) + "." + ComboBox2.List(ComboBox2.L istIndex)
MsgBox clk
Dim conn As ADODB.Connection
Dim rec As ADODB.Recordset
Set conn = New ADODB.Connection
conn.Open "Driver={Microsoft ODBC for Oracle};" & _
"Server=;" & _
"Uid=;" & _
"Pwd=;"
Set rec = New ADODB.Recordset
rec.Open "SELECT * FROM project_data3 where ang_kost1='" & clk & "'", conn
i = 22
ActiveCell.Offset(1, 0).Range("A1").Select
Range("A24:A" & i).Select
Selection.ClearContents
Selection.ClearOutline
Tabelle2.Cells(i, 1) = (rec.Fields("ver_nr1").Val ue)
Tabelle2.Cells(i, 2) = (rec.Fields("ver_bes1").Va lue)
While Not rec.EOF
i = i + 1
Tabelle2.Cells(i, 1) = (rec.Fields("stn_nr1").Val ue)
Tabelle2.Cells(i, 3) = (rec.Fields("ua_nr1").Valu e)
Tabelle2.Cells(i, 4) = (rec.Fields("psp1").Value)
Tabelle2.Cells(i, 6) = (rec.Fields("prod_bes1").V alue)
Tabelle2.Cells(i, 7) = (rec.Fields("ve1").Value)
Range("A24:A" & i).Select
Selection.ClearOutline
Selection.Rows.Group
Tabelle2.Cells(i, 1).EntireRow.Select
With Selection.Interior
.ColorIndex = 8
.Pattern = xlSolid
End With
rec.MoveNext
Wend
rec.Close
Set rec = Nothing
End Sub
Private Sub CommandButton3_Click()
Dim clk As String
Dim i As Integer
clk = ComboBox1.List(ComboBox1.L
MsgBox clk
Dim conn As ADODB.Connection
Dim rec As ADODB.Recordset
Set conn = New ADODB.Connection
conn.Open "Driver={Microsoft ODBC for Oracle};" & _
"Server=;" & _
"Uid=;" & _
"Pwd=;"
Set rec = New ADODB.Recordset
rec.Open "SELECT * FROM project_data3 where ang_kost1='" & clk & "'", conn
i = 22
ActiveCell.Offset(1, 0).Range("A1").Select
Range("A24:A" & i).Select
Selection.ClearContents
Selection.ClearOutline
Tabelle2.Cells(i, 1) = (rec.Fields("ver_nr1").Val
Tabelle2.Cells(i, 2) = (rec.Fields("ver_bes1").Va
While Not rec.EOF
i = i + 1
Tabelle2.Cells(i, 1) = (rec.Fields("stn_nr1").Val
Tabelle2.Cells(i, 3) = (rec.Fields("ua_nr1").Valu
Tabelle2.Cells(i, 4) = (rec.Fields("psp1").Value)
Tabelle2.Cells(i, 6) = (rec.Fields("prod_bes1").V
Tabelle2.Cells(i, 7) = (rec.Fields("ve1").Value)
Range("A24:A" & i).Select
Selection.ClearOutline
Selection.Rows.Group
Tabelle2.Cells(i, 1).EntireRow.Select
With Selection.Interior
.ColorIndex = 8
.Pattern = xlSolid
End With
rec.MoveNext
Wend
rec.Close
Set rec = Nothing
End Sub
ASKER
with every new click i want to display new contents and colour, i mean only the rows with contents shld be coloured and
If there are no other data on the sheet use this
Private Sub ComboBox1_Click()
Tabelle2.UsedRange.Select
Selection.Clear
Selection.ClearFormats
End Sub
If there other data then you must clear only the range you want
Private Sub ComboBox1_Click()
Tabelle2.range("Put your range here").Select
Selection.Clear
Selection.ClearFormats
End Sub
Private Sub ComboBox1_Click()
Tabelle2.UsedRange.Select
Selection.Clear
Selection.ClearFormats
End Sub
If there other data then you must clear only the range you want
Private Sub ComboBox1_Click()
Tabelle2.range("Put your range here").Select
Selection.Clear
Selection.ClearFormats
End Sub
ASKER
is my question clear????
ASKER
if you see my code, i just want to replace the range, for eg:-
when im selecting one value from combobox and pressing button, im displaying valies on the cells dynamically, and these cells are having the values and are coloured, now when i select a new one, im able to clear the values and put the new ones but im not able to clear the colour,
what i want is the rows are coloured only till the values are there, so everytime i need to clear the colour and colour it new
when im selecting one value from combobox and pressing button, im displaying valies on the cells dynamically, and these cells are having the values and are coloured, now when i select a new one, im able to clear the values and put the new ones but im not able to clear the colour,
what i want is the rows are coloured only till the values are there, so everytime i need to clear the colour and colour it new
I thinnk it is now. I will post in 5 to 10 mins I am in the middle of something now
ASKER
ok
Try this
After the line
MsgBox clk
add this
Rows("22:" & i).Select
Selection.Interior.ColorIn dex = xlNone
Selection.ClearContents
After the line
MsgBox clk
add this
Rows("22:" & i).Select
Selection.Interior.ColorIn
Selection.ClearContents
ASKER
Rows("22:" & i).Select
Selection.Interior.ColorIn dex = xlNone
Selection.ClearContents
im getting error as type incompatible
Selection.Interior.ColorIn
Selection.ClearContents
im getting error as type incompatible
Sorry. You already have code that clears content like this
Range("A24:A" & i).Select
Selection.ClearContents
Selection.ClearOutline
add this line after that code
Selection.Interior.ColorIn dex = xlNone
If you still get the error replace the line I gave above with
Selection.Interior.ColorIn dex = xlColorIndexNone
If it is not covering the range you want then adjust the 24 to something else 22 or 23
Range("A24:A" & i).Select
Selection.ClearContents
Selection.ClearOutline
add this line after that code
Selection.Interior.ColorIn
If you still get the error replace the line I gave above with
Selection.Interior.ColorIn
If it is not covering the range you want then adjust the 24 to something else 22 or 23
I am off to lunch, back in an hour or so
ASKER
i have tried both, its not clearing the colour
................
Tabelle2.Range("a23:a500") .Interior. ColorIndex = 2
Tabelle2.Range("b23:b500") .Interior. ColorIndex = 2
Tabelle2.Range("c23:c500") .Interior. ColorIndex = 2
i dont know right or wrong, im doing something like this and its working,
................
Tabelle2.Range("a23:a500")
Tabelle2.Range("b23:b500")
Tabelle2.Range("c23:c500")
i dont know right or wrong, im doing something like this and its working,
Put a breakpoint on the line after
MsgBox clk
Then tell me the value of i at that point - do msgbox i
Also where I said this
Selection.Interior.ColorIn dex = xlNone
instead try
Selection.ClearFormats
MsgBox clk
Then tell me the value of i at that point - do msgbox i
Also where I said this
Selection.Interior.ColorIn
instead try
Selection.ClearFormats
ASKER
Private Sub CommandButton3_Click()
Dim clk As String
Dim i As Integer
clk = ComboBox1.List(ComboBox1.L istIndex) + "." + ComboBox2.List(ComboBox2.L istIndex)
MsgBox clk
MsgBox i
value of i is 0
Dim clk As String
Dim i As Integer
clk = ComboBox1.List(ComboBox1.L
MsgBox clk
MsgBox i
value of i is 0
Stupid me!!!!!
Change
Dim i As Integer
to
Static i As Integer
Change
Dim i As Integer
to
Static i As Integer
ASKER
the value of i is changing according to the last cell, but the colour is not going
i mean i selected one value and it coloured 20 cells and i showed value 20 and
i selected another value it had around 15 values, and the remaining 15 - 20 cells are still having colour
i mean i selected one value and it coloured 20 cells and i showed value 20 and
i selected another value it had around 15 values, and the remaining 15 - 20 cells are still having colour
Please post code again as it is now from beginning up to this line
While Not rec.EOF
While Not rec.EOF
ASKER
heres my complete code
Private Sub CommandButton3_Click()
Dim clk As String
Static i As Integer
clk = ComboBox1.List(ComboBox1.L istIndex) + "." + ComboBox2.List(ComboBox2.L istIndex)
MsgBox clk
'MsgBox i
Dim conn As ADODB.Connection
Dim rec As ADODB.Recordset
Set conn = New ADODB.Connection
conn.Open "Driver={Microsoft ODBC for Oracle};" & _
"Server=;" & _
"Uid=;" & _
"Pwd=;"
Set rec = New ADODB.Recordset
rec.Open "SELECT * FROM project_data3 where ang_kost1='" & clk & "'ORDER BY stn_nr1 ASC", conn
i = 22
ActiveCell.Offset(1, 0).Range("A1").Select
Call clear_rows
Range("A24:A" & i).Select
Selection.ClearContents
Selection.ClearOutline
Selection.ClearFormats
While Not rec.EOF
Tabelle2.Range("b22") = (rec.Fields("ver_nr1").Val ue)
Tabelle2.Range("e22") = (rec.Fields("ver_bes1").Va lue)
i = i + 1
Tabelle2.Cells(i, 1) = (rec.Fields("stn_nr1").Val ue)
Tabelle2.Cells(i, 3) = (rec.Fields("ua_nr1").Valu e)
Tabelle2.Cells(i, 4) = (rec.Fields("psp1").Value)
Tabelle2.Cells(i, 6) = (rec.Fields("prod_bes1").V alue)
Tabelle2.Cells(i, 7) = (rec.Fields("ve1").Value)
Tabelle2.Cells(i, 8) = (rec.Fields("ve1").Value)
Range("A24:A" & i).Select
Selection.ClearOutline
Selection.Rows.Group
Selection.HorizontalAlignm ent = xlCenter
Selection.Font.Bold = True
Tabelle2.Cells(i, 1).EntireRow.Select
With Selection.Interior
.ColorIndex = 8
.Pattern = xlSolid
End With
rec.MoveNext
Wend
rec.Close
Set rec = Nothing
Private Sub CommandButton3_Click()
Dim clk As String
Static i As Integer
clk = ComboBox1.List(ComboBox1.L
MsgBox clk
'MsgBox i
Dim conn As ADODB.Connection
Dim rec As ADODB.Recordset
Set conn = New ADODB.Connection
conn.Open "Driver={Microsoft ODBC for Oracle};" & _
"Server=;" & _
"Uid=;" & _
"Pwd=;"
Set rec = New ADODB.Recordset
rec.Open "SELECT * FROM project_data3 where ang_kost1='" & clk & "'ORDER BY stn_nr1 ASC", conn
i = 22
ActiveCell.Offset(1, 0).Range("A1").Select
Call clear_rows
Range("A24:A" & i).Select
Selection.ClearContents
Selection.ClearOutline
Selection.ClearFormats
While Not rec.EOF
Tabelle2.Range("b22") = (rec.Fields("ver_nr1").Val
Tabelle2.Range("e22") = (rec.Fields("ver_bes1").Va
i = i + 1
Tabelle2.Cells(i, 1) = (rec.Fields("stn_nr1").Val
Tabelle2.Cells(i, 3) = (rec.Fields("ua_nr1").Valu
Tabelle2.Cells(i, 4) = (rec.Fields("psp1").Value)
Tabelle2.Cells(i, 6) = (rec.Fields("prod_bes1").V
Tabelle2.Cells(i, 7) = (rec.Fields("ve1").Value)
Tabelle2.Cells(i, 8) = (rec.Fields("ve1").Value)
Range("A24:A" & i).Select
Selection.ClearOutline
Selection.Rows.Group
Selection.HorizontalAlignm
Selection.Font.Bold = True
Tabelle2.Cells(i, 1).EntireRow.Select
With Selection.Interior
.ColorIndex = 8
.Pattern = xlSolid
End With
rec.MoveNext
Wend
rec.Close
Set rec = Nothing
This block of code
Range("A24:A" & i).Select
Selection.ClearContents
Selection.ClearOutline
Selection.ClearFormats
Should go after
msgbox clk
Do that and let me know what you get
Range("A24:A" & i).Select
Selection.ClearContents
Selection.ClearOutline
Selection.ClearFormats
Should go after
msgbox clk
Do that and let me know what you get
ASKER
its working only for the first A column
OK
Change this
Range("A24:A" & i).Select
to
Range("A24:D" & i).Select
Change this
Range("A24:A" & i).Select
to
Range("A24:D" & i).Select
ASKER
ok its working.......thanks a lot
Cool. Please if you need another help with this open a new question. I helped as much as I can on this one
ASKER
ya ill open a new question,
thanks a lot again
thanks a lot again
ASKER
Hello gbzhhu
could you please refre to this new post, thanks
https://www.experts-exchange.com/questions/21397231/displaying-data-in-a-distinct-format-in-excel-sheet.html
could you please refre to this new post, thanks
https://www.experts-exchange.com/questions/21397231/displaying-data-in-a-distinct-format-in-excel-sheet.html
While Not rec.EOF
i = i + 1
Tabelle2.Cells(i, 1) = (rec.Fields("ver_nr1").Val
Tabelle2.Cells(i, 2) = (rec.Fields("ver_bes1").Va
i = i + 1 'this makes room for the values you want to enter
Tabelle2.Cells(i, 1) = (rec.Fields("New_Field_Her
Tabelle2.Cells(i, 2) = (rec.Fields("New_Field_Her
rec.MoveNext
Wend