How to populate listbox1 (without userform) with different colums from different sheets - textbox

My listbox is populated with 1 column of a specific sheet.
How can I get a second and third column in my listbox?
I mean... Column B from sheet1, column C from sheet2 and column B from sheet3, each with a second column from the sheets.
In this case I have a textbox where you can type your search.
This already works for me for just 1 specific column of 1 sheet:
Private Sub textbox1_change() 'zoekt via zoekterm boxpositie de mogelijke boxposities op
Dim i As Long
Dim x As Integer
Dim Sheet1 As Worksheet
TextBox1 = Format(StrConv(TextBox1, vbUpperCase))
Set Sheet1 = Worksheets("Cytolab")
a = TextBox1.TextLength
ListBox1.Clear
ListBox1.Height = 101
ListBox1.Top = 290
ListBox1.Width = 512
For i = 5 To Sheet1.Range("B238").End(xlUp).row
For x = 1 To Len(Sheet1.Cells(i, 2))
If UCase(Mid(Sheet1.Cells(i, 2), x, a)) = TextBox1 And TextBox1 <> "" Then
ListBox1.AddItem CStr(Sheet1.Cells(i, 2)) 'CStr() toegevoegd
ListBox1.List(ListBox1.ListCount - 1, 1) = "" & Sheet1.Cells(i, 3) & " · " & Sheet1.Cells(i, 7) & " · " & Sheet1.Cells(i, 5) & " · " & Sheet1.Cells(i, 4)
ListBox1.List(ListBox1.ListCount - 1, 2) = "" & Sheet1.Cells(i, 9)
End If
Next x
Next i
End Sub
Thank you.

Related

Index and Concat / Concatenate from another sheet

I have a data sheet which i want to index pull into another sheet and also concanate or concat 2 or more columns with array formula.
sheet link here
https://docs.google.com/spreadsheets/d/1GUI-Gl7HDNGg5V2wM4ossUn46cp7VHRBZ_t4la2gDH0/edit?usp=sharing
data sheet https://docs.google.com/spreadsheets/d/1GUI-Gl7HDNGg5V2wM4ossUn46cp7VHRBZ_t4la2gDH0/edit#gid=0
result required sample sheet https://docs.google.com/spreadsheets/d/1GUI-Gl7HDNGg5V2wM4ossUn46cp7VHRBZ_t4la2gDH0/edit#gid=1226812843
you can see in result sheet column B and F which are merged from "data sheet column b c d and h i simultaneously"
Use an { array expression }. Insert > Sheet and put this formula in cell A1 of the new sheet:
=arrayformula(
{
DATA!A1:A,
trim(
DATA!B1:B & " " &
if( iserror(search(DATA!C1:C, DATA!B1:B)), DATA!C1:C, "" ) & " " &
if( iserror(search(DATA!D1:D, DATA!B1:B)), DATA!D1:D, "" )
),
DATA!E1:G,
trim(DATA!H1:H & if(len(DATA!I1:I), " / " & DATA!I1:I, "")),
DATA!J1:U
}
)
The formula will only append the values in columns C and D to the value in column B when they do not not already appear in the value in column B.
the prior answer is ok but did you know...
so your issue can be solved as:
=BYROW(DATA!A2:INDEX(DATA!A:A, COUNTA(DATA!A:A)),
LAMBDA(a, {a, TEXTJOIN(" ", 1, OFFSET(a,,1,,3)), OFFSET(a,,4,,3),
TEXTJOIN(" / ", 1, OFFSET(a,,7,,2)), OFFSET(a,,9,,11)}))

How can I generate an array of numbers between multiple ranges defined in separate cells in Sheet?

A1: 1 | B1: 4
A2: 3 | B2: 6
How can I get {1, 2, 3, 3, 4, 4, 5, 6} out of this?
– – – – – –
I know this way:
=ArrayFormula({ROW(INDIRECT(A1&":"&B1)); ROW(INDIRECT(A2&":"&B2))})
That does the job perfectly but what if I don't know, how many ranges there will be? I want to generate an array of all the numbers between values specified in cells from A1:B1 all the way to A:B.
Thank you in advance!
Here is a relatively simple formula to generate the array you're talking about based on an infinite number of ranges in columns A and B.
=ARRAYFORMULA(QUERY(SPLIT(FLATTEN(SEQUENCE(1,MAX(B1:B10-A1:A10)+1,0)+A1:A10&"|"&B1:B10),"|",0,0),"Select Col1 where Col1<=Col2 order by Col1",0))
You can see it demonstrated in the tab called Demo 2 on this sheet.
In Excel 365 with your data in columns A and B, pick a cell and enter:
="{" & TEXTJOIN(",",TRUE,SEQUENCE(,MAX(A:B),MIN(A:B))) & "}"
EDIT#1:
Try this VBA macro:
Sub MakeArray()
Dim I As Long, N As Long, J, k
Dim strng As String
Dim arr As Variant
N = Cells(Rows.Count, "A").End(xlUp).Row
For I = 1 To N
For J = Cells(I, 1) To Cells(I, 2)
strng = strng & "," & J
Next J
Next I
strng = Mid(strng, 2)
strng = "{" & Join(fSort(Split(strng, ",")), ",") & "}"
MsgBox strng
End Sub
Public Function fSort(ByVal arry)
Dim I As Long, J As Long, Low As Long
Dim Hi As Long, Temp As Variant
Low = LBound(arry)
Hi = UBound(arry)
J = (Hi - Low + 1) \ 2
Do While J > 0
For I = Low To Hi - J
If arry(I) > arry(I + J) Then
Temp = arry(I)
arry(I) = arry(I + J)
arry(I + J) = Temp
End If
Next I
For I = Hi - J To Low Step -1
If arry(I) > arry(I + J) Then
Temp = arry(I)
arry(I) = arry(I + J)
arry(I + J) = Temp
End If
Next I
J = J \ 2
Loop
fSort = arry
End Function
The macro:
creates a comma-separated string from each A/B pair
sorts the string
outputs the string

Get all Rows from QUERY() into one cell in a Google Spreadsheet

I have the following formula in a spreadsheet:
=IFERROR( JOIN( CHAR(10), QUERY(Schedule!$A$2:$E, "SELECT C, D, E Where A = '" & B$2 & "' AND B = timeofday '" & text($A4, "HH:MM:SS") & "' AND C = '" & $C$1 & "'", -1)),)
It works great when it returns one row. It does not work if it returns multiple rows. How can I get it to use all rows returned with a CHAR(10) included between rows as well as columns. Basically I want all the returned data separated by line breaks. So when the QUERY returns
Item1 Item2 Item3
Item1A Item2A Item3A
it is changed to
Item1
Item2
Item3
Item1A
Item2A
Item3A
My goal is to put all the returned data in 1 cell with a line break between each item. Any way I can make this happen?
Here is a copy of the file. Cells B3 to F4 are good sample cells where the formula reside.
The solution is imperfect, it adds extra spaces before each line:
Item1 Item2 Item3
Item1A Item2A Item3A
^ spaces
Step1
Get origilal formula + extra column in query:
=QUERY(data, "SELECT C, D, E, '##' Where" & ... & "' label '##' ''", -1)
The result:
Item1 Item2 Item3 ##
Item1A Item2A Item3A ##
Step2
Replace "##" with char(10)
=ARRAYFORMULA(SUBSTITUTE(step1Formula,"##",char(10)))
Item1 Item2 Item3
Item1A Item2A Item3A
^ new lines
Step3
Use concatenate:
=ArrayFormula(" "&TRIM(CONCATENATE(" "&B16:E17)))
Final formula
=ArrayFormula(" "&TRIM(CONCATENATE(" "&SUBSTITUTE(QUERY(Schedule!$A$2:$E, "SELECT C, D, E, '##' Where A = '" & B$2 & "' AND B = timeofday '" & text($A3, "HH:MM:SS") & IF(OR($C$1 = "*",ISBLANK($C$1)), "", "' AND C = '" & $C$1) & IF(OR($F$1 = "*",ISBLANK($F$1)), "", "' AND E = '" & $F$1) & "' label '##' ''", -1),"##",char(10)))))
Shared file:
https://docs.google.com/spreadsheets/d/1otcqvkXb5H3WTSi_exKw9UUcRqN8MKBZ5JYCmTLAWdQ/edit?usp=sharing
I know this is not an elegant solution, but it will help you in your case. Enter this formula at B3 and then copy and paste it onto other cells.
=iferror(join(char(10), query(Schedule!$A$2:$E, "select C,D,E where A='"&B$2&"' and B=timeofday '"&text($A3, "hh:mm:ss")&"' limit 1 offset 0")),"")
&iferror(char(10)&char(10) & join(char(10), query(Schedule!$A$2:$E, "select C,D,E where A='"&B$2&"' and B=timeofday '"&text($A3, "hh:mm:ss")&"' limit 1 offset 1")),"")
&iferror(char(10)&char(10) & join(char(10), query(Schedule!$A$2:$E, "select C,D,E where A='"&B$2&"' and B=timeofday '"&text($A3, "hh:mm:ss")&"' limit 1 offset 2")),"")
&iferror(char(10)&char(10) & join(char(10), query(Schedule!$A$2:$E, "select C,D,E where A='"&B$2&"' and B=timeofday '"&text($A3, "hh:mm:ss")&"' limit 1 offset 3")),"")
&iferror(char(10)&char(10) & join(char(10), query(Schedule!$A$2:$E, "select C,D,E where A='"&B$2&"' and B=timeofday '"&text($A3, "hh:mm:ss")&"' limit 1 offset 4")),"")
Basically you cannot concat result strings with google query(), so instead I'd fetch one row at a time using limit 1 offset 0, limit 1 offset 1, limit 1 offset 2, and so on. Maximum is 5 in this case. Sample sheet is here.

VBA parse string Place values to new columns

I have a sheets with the rows of data like.
NOM(LSL,USL)=207.3980(206.1990,208.5970) NOM(LSL,USL)=207.3980(206.1990,208.5970) NOM(LSL,USL)=18.8200(18.4400,19.2100)
I would like to just grab the Values and place them in their own cells like
207.3980 207.3980 18.8200
206.1990 206.1990 18.4400
208.5970 208.5970 19.2100
I continue to recieve "ByRef Argument Mismatch" errors. I believe relating to how I am defining the reference cell.
Sub Parse_Replace()
Dim i As Double
Dim ws As Worksheet
Set ws = ThisWorkbook.ActiveSheet
Dim Col As Range
Dim rLastCell As Range
Set rLastCell = ws.Cells.Find(What:="*", After:=ws.Cells(1, 1), LookIn:=xlFormulas, LookAt:= _
xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlPrevious, MatchCase:=False)
For i = rLastCell.Column To 1 Step -1
Col = ColLett(rLastCell.Column)
Columns(i).Cells(4) = SplitString(Col3, ",", 4)
Columns(i).Cells(5) = SplitString(Col3, ",", 5)
Columns(i).Cells(6) = SplitString(Col3, ",", 6)
Next i
End Sub
Function ColLett(Col As Integer) As String
If Col > 26 Then
ColLett = ColLett((Col - (Col Mod 26)) / 26) + Chr(Col Mod 26 + 64)
Else
ColLett = Chr(Col + 64)
End If
End Function
Function SplitString(pValue As String, pChar As String, pIndex As Integer) As Variant
Dim YString As Variant
YString = Replace(Replace(Replace(Replace(pValue, " ", ""), "=", ""), "(", ","), ")", ",")
SplitString = Split(YString, pChar)(pIndex - 1)
End Function
Process
Establish number of Columns with Data
Loop through each column
Convert column index to Column with ColLett
Set cell value with SplitString
Loop
Thank You
EDIT : replaced SplitString value with inteded.
You declare Col to be a range here:
Dim Col As Range
You then try to set Col to a string here:
Col = ColLett(rLastCell.Column)
When you set a range you have to set it to a range. Furthermore, you have to use the SET keyword to do so:
Set Col = <a range>
When you set that Col you set it only to the rLastCell.Column repeatedly in each loop of your For. If you just need that column letter for the last column, then do it before entering your for loop.
All of that is pointless anyway. At no point do you use the Column letter that you went through the trouble retrieving in your function. And really, for what you are doing you don't need the Column Letter. Column Letters are for humans; the column number is what is important in VBA any how.

How to resize side by side controls in MS ACCESS 2007

I have a form in which there are various fields, for ex. Two textboxes are side by side.
These 2 textbox have anchor property left,top and other right,top.
Now when I resize the form the controls are aligned to left and the other textbox to right.
But when as screen is maximized it leaves a blank space in between these two textboxes.
So then I made the anchor property of both textbox to both,both the controls overlapped.
PS: working on MS ACCESS 2007.
anchoring property above is Horizontal, Vertical
EDIT : In Normal window
_______________________Min Max Close_
| First_Name TEXTBOX Last_Name TEXTBOX |
|_______________________________|
When Maximized to whole screen it gives me
_____________________________________Min Max Close_
| First_Name TEXTBOX ............................. Last_Name TEXTBOX |
|______________________________________________|
And I need this way as below
_____________________________________Min Max Close_
| F i r s t_N a m e T E X T B O X ........ L a s t_N a m e T E X T B O X |
|______________________________________________|
I am trying to explain by doing all this as I am not allowed to upload a image, Sorry for that....
Paste the following code into your form, change the field names, and see what happens. The two fields will 'grow' as you increase the form width, yet maintain their Anchor. Note: I updated on 3/3 to handle the field labels.
Option Compare Database
Option Explicit
Dim fviInsideWidth As Integer
Dim fviSaveInsideWidth As Integer
Dim fviFormWidth As Integer
Dim fviFldWidth As Integer
Dim fviFieldGap As Integer
Dim fviRemainder As Integer
Dim fviLblWidth As Integer
Dim fviRLblToTxt As Integer
Dim fvstrLLabel As String
Dim fvstrRLabel As String
Private Sub Form_Open(Cancel As Integer)
fviSaveInsideWidth = Me.InsideWidth
fviInsideWidth = Me.InsideWidth
fviFormWidth = Me.Width
fviFldWidth = Me.fldLeft.Width + Me.fldRight.Width
fviRemainder = fviInsideWidth - fviFldWidth
fviFieldGap = Me.fldRight.Left - (Me.fldLeft.Left + Me.fldLeft.Width)
fvstrLLabel = Me.fldLeft.Controls.Item(0).Name
fvstrRLabel = Me.fldRight.Controls.Item(0).Name
fviLblWidth = Me.Controls(fvstrRLabel).Width
fviRLblToTxt = Me.fldRight.Left - Me.Controls(fvstrRLabel).Left
'Debug.Print "Open - InsideWidth = " & fviInsideWidth & " Fields: " & fviFldWidth & " Remainder: " & fviRemainder
'Debug.Print "Open - Form Width = " & Me.Width & vbTab & "Diff = " & fviInsideWidth - fviFormWidth
End Sub
Private Sub Form_Close()
Me.fldLeft.Width = fviFldWidth
Me.fldRight.Width = fviFldWidth
Me.InsideWidth = fviSaveInsideWidth
End Sub
Private Sub Form_Resize()
Dim ifldWidth As Integer
Dim ifrmWidth As Integer
fviInsideWidth = Me.InsideWidth
ifrmWidth = fviInsideWidth - 1110
Me.Width = ifrmWidth
ifldWidth = Int((fviInsideWidth - fviRemainder) / 2)
Me.fldLeft.Width = ifldWidth
Me.fldRight.Left = Me.fldLeft.Left + Me.fldLeft.Width + fviFieldGap
Me.Controls(fvstrRLabel).Left = Me.fldRight.Left - fviRLblToTxt
Me.fldRight.Width = ifldWidth
'Debug.Print "Resize - InsideWidth = " & fviInsideWidth & vbTab & "Form Width = " & Me.Width & " Flds: " & ifldWidth & " Right=" & Me.fldLeft.Left + Me.fldLeft.Width + fviFieldGap
'Debug.Print "Resize Form: " & Me.Width & " Flds: " & ifldWidth
Me.Repaint
End Sub

Resources