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
Microsoft OfficeVBAMicrosoft Excel

Avatar of undefined
Last Comment
Subodh Tiwari (Neeraj)

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Subodh Tiwari (Neeraj)

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
LUIS FREUND

ASKER
AWESOME!  MANY THANKS!
Subodh Tiwari (Neeraj)

You're welcome Luis! :)
LUIS FREUND

ASKER
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
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Subodh Tiwari (Neeraj)

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