show specific currency and numberformat in listbox & textbox

abdelfattah

Well-known Member
Joined
May 3, 2019
Messages
1,433
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
hi

I create specific currency as in sheet in columns E,F "LYD" by cell format . so waht I want when show the userform should show number format in list box based on columns D,E,F but the currency based on columns E,F also the same thing when write numbers in textbox2,3 should show numberformat and currency .

this is the whole code
VBA Code:
Dim arr



Private Sub UserForm_Initialize()
With Sheets("sheet1")
Set rg = .Range("A2:F15")
arr = rg
End With
    With ListBox1
    .ColumnCount = 6
    .ColumnWidths = "80,120,80,80,80,80,80,80,80"
    .List = arr
    End With

End Sub

Private Sub textbox1_Change()
Dim rw()
    For i = 1 To UBound(arr)
    If LCase(arr(i, 2)) Like "*" & LCase(TextBox1.Value) & "*" Then
    ReDim Preserve rw(p)
    rw(p) = Application.Index(arr, i, 0)
    p = p + 1
    End If
    Next
 
   If p = 0 Then MsgBox "NO MATCH": Exit Sub
With ListBox1
    If p > 1 Then
        .List = Application.Transpose(Application.Transpose(rw))
    Else
        .Column = Application.Transpose(rw)
    End If
End With
End Sub

Sub FormatLB()
With ListBox1
For i = 0 To .ListCount - 1
.List(i, 1) = Format(LB.List(i, 1), "dd/mm/yyyy")
.List(i, 2) = LB.List(i, 2)
.List(i, 3) = LB.List(i, 3)
.List(i, 4) = LB.List(i, 4)
.List(i, 5) = LB.List(i, 5)
.List(i, 6) = LB.List(i, 6)

Next
End With
End Sub
structure my data in sheet and userform
k.PNG
 
Did not look at all your code
if declared the arr variable at procedure level as shown in my post then that needs to be deleted as you already have declared it at module level

Dave
 
Upvote 0

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
sorry ! about this point you're right , but even if delete it .it stiil shows the error .
 
Upvote 0
this is what existed in your updating . and still show the error
 
Upvote 0
try changing this line

VBA Code:
For i = 1 To UBound(arr)

to this

VBA Code:
For i = 1 To UBound(arr,1)

Dave
 
Upvote 0
nothing changes . the same error

Think this is a different issue but publish all the code behind your form or better, place copy of your workbook on filesharing site & provide a link to it

Dave
 
Upvote 0
As I suspected, you have deleted the Declaration at module level

the line needs to be at the VERY TOP of your forms code page

VBA Code:
Dim arr()   As Variant

and DELETE it in the UserForm_Intialize event

also, return then line that was erroring back to its original state

VBA Code:
For i = 1 To UBound(arr)

Dave
 
Upvote 0
well done ! but I have question about declare this
VBA Code:
Dim arr()   As Variant
what's the difference if I put module level above or inside the UserForm_Intialize event?
 
Upvote 0

Forum statistics

Threads
1,216,054
Messages
6,128,516
Members
449,456
Latest member
SammMcCandless

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top