Link to home
Start Free TrialLog in
Avatar of LUIS FREUND
LUIS FREUND

asked on

Number format VBA to two different tabs in workbook

How can I apply this number format code to different sheets:

On "MAIN_PN" tab I have this code that works great But I need to apply it to "MAIN" tab O27:O30 as well.

Sub FixDates()
   Columns("I").TextToColumns
   Range("I4:J650", Cells(Rows.Count, "I").End(xlUp)).NumberFormat = "mm/dd/yy"
End Sub
ASKER CERTIFIED SOLUTION
Avatar of Subodh Tiwari (Neeraj)
Subodh Tiwari (Neeraj)
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of LUIS FREUND
LUIS FREUND

ASKER

AWESOME!  MANY THANKS!
You're welcome Luis! :)
Oh this came up......runtime error

I only get it when there is nothing in column O27:O30.  There are instances that this area will not get populated at times.
C--Users-lfreund-Pictures-error.JPG
C--Users-lfreund-Pictures-vba.JPG
Okay, try this...
Sub FixDates()
On Error Resume Next
With Sheets("MAIN_PN")
    .Columns("I").TextToColumns
    .Range("I4:J" & .Cells(Rows.Count, "I").End(xlUp).Row).NumberFormat = "mm/dd/yy"
End With
With Sheets("MAIN")
    .Range("O27:O30").TextToColumns
    .Range("O27:O30").NumberFormat = "mm/dd/yy"
End With
End Sub

Open in new window