I write Cobol format in VBA excel please help me with such as?

Faozan

Banned user
Joined
May 14, 2023
Messages
25
Office Version
  1. 365
  2. 2021
  3. 2019
  4. 2016
  5. 2013
  6. 2011
  7. 2010
  8. 2007
  9. 2003 or older
Platform
  1. Windows
  2. MacOS
  3. Mobile
  4. Web
Such as asdfghjk =>asd-fg-hijk (alphanumeric)
1234567 => 12-345-67 (numeric)
 
Change references where required.
Code:
Sub Here_We_Go()
Dim c As Range
    For Each c In Sheets("Sheet1").Range("A2:A" & Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row)
        If IsNumeric(c.Value) Then
            With Sheets("Sheet2").Cells(Rows.Count, 1).End(xlUp).Offset(1)
                .NumberFormat = "@"
                .Value = Left(c, 4) & "-" & Mid(c, 5, 3) & "-" & Mid(c, 8)
            End With
        Else
            With Sheets("Sheet3").Cells(Rows.Count, 1).End(xlUp).Offset(1)
                .Value = Left(c, 2) & "-" & Mid(c, 3, 2) & "-" & Mid(c, 5)
            End With
        End If
    Next c
End Sub
 
Upvote 0
Solution

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Change references where required.
Code:
Sub Here_We_Go()
Dim c As Range
    For Each c In Sheets("Sheet1").Range("A2:A" & Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row)
        If IsNumeric(c.Value) Then
            With Sheets("Sheet2").Cells(Rows.Count, 1).End(xlUp).Offset(1)
                .NumberFormat = "@"
                .Value = Left(c, 4) & "-" & Mid(c, 5, 3) & "-" & Mid(c, 8)
            End With
        Else
            With Sheets("Sheet3").Cells(Rows.Count, 1).End(xlUp).Offset(1)
                .Value = Left(c, 2) & "-" & Mid(c, 3, 2) & "-" & Mid(c, 5)
            End With
        End If
    Next c
End Sub
Hi, How to create fix length and add currency numbers such as 123456789 to 6789.00 or 1234.00
 
Upvote 0
Yes what?
Should that be 12 or 12.00 or 1200.00
Or should it be $1200.00?
 
Upvote 0
Upvote 0
Do me a favor please. Don't quote unless it is absolutely required, which to my knowledge it very seldom is.
Refer to Post numbers and/or member's name.
 
Upvote 0
Do me a favor please. Don't quote unless it is absolutely required, which to my knowledge it very seldom is.
Refer to Post numbers and/or member's name
Member’s name
 
Upvote 0
Code:
Sub Here_We_Go()
Dim c As Range
    For Each c In Sheets("Sheet1").Range("C2:C" & Sheets("Sheet1").Cells(Rows.Count, 3).End(xlUp).Row)
        If IsNumeric(c.Value) Then
            With Sheets("Sheet2").Cells(Rows.Count, 1).End(xlUp).Offset(1)
                .NumberFormat = "@"
                .Value = Left(c, 4) & ".00" & "-" & Mid(c, 5, 3) & ".00" & "-" & Mid(c, 8) & ".00"
            End With
        Else
            With Sheets("Sheet3").Cells(Rows.Count, 1).End(xlUp).Offset(1)
                .Value = Left(c, 2) & "-" & Mid(c, 3, 2) & "-" & Mid(c, 5)
            End With
        End If
    Next c
End Sub

What I mean by Post #18 is to NOT use the quote button.
 
Upvote 0

Forum statistics

Threads
1,224,817
Messages
6,181,148
Members
453,021
Latest member
Justyna P

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