change column from date to number format and opposite after copy from form

MKLAQ

Active Member
Joined
Jan 30, 2021
Messages
397
Office Version
  1. 2016
Platform
  1. Windows
Hello
I have this code to copy data from listbox to sheet . in first column contains date based on selected item from combobox when populate date will be like this DD/MM/YYYY then will show column A and it's ok ,but my problem when select optionbutton1 or optionbutton2 and populate numbers in first column like this 1,2,3 .... then should copy to column A like this 1,2,3.... but the problem will show like this 45155 .
so I want when copy data from listbox date in first column then should show date in column A is , if when copy data from listbox numbers in first column then should show number in column A .
VBA Code:
Private Sub CommandButton2_Click()
With Sheets("sheet1")
.Range("a2").CurrentRegion.ClearContents

If OptionButton1.Value = True Or OptionButton2.Value = True Then

.Range("A" & .Rows.Count).End(xlUp).Offset(0).Resize(ListBox1.ListCount, 6) = ListBox1.List
  
    ElseIf ComboBox1.Value <> "" Then

.Range("A" & .Rows.Count).End(xlUp).Offset(0).Resize(ListBox1.ListCount, 6) = ListBox1.List
    .Columns(1).NumberFormat = " General"
    
End If

End With

Sheets("sheet1").Range("a1").CurrentRegion.PrintOut
End Sub
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
it's solved in another forum by MatrixMan
VBA Code:
Private Sub CommandButton1_Click()
    With Sheets("sheet1")
        .Range("a2").CurrentRegion.ClearContents
        If OptionButton1.Value = True Then
            .Range("A" & .Rows.Count).End(xlUp).Offset(0).Resize(ListBox1.ListCount, 6) = ListBox1.List
            .Columns(1).NumberFormat = "mmm dd yyyy"    '<-- set the date format.
        ElseIf OptionButton2.Value = True Then
            .Range("A" & .Rows.Count).End(xlUp).Offset(0).Resize(ListBox1.ListCount, 6) = ListBox1.List
            .Columns(1).NumberFormat = " General"
        End If
    End With
   
    Sheets("sheet1").Range("a1").CurrentRegion.PrintOut
   
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,215,076
Messages
6,122,984
Members
449,092
Latest member
Mr Hughes

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