Edit code vba

sofas

Active Member
Joined
Sep 11, 2022
Messages
468
Office Version
  1. 2019
Platform
  1. Windows
Hello, can I know where the error is in the code?

Code:
Sub Macro1()
Dim LastRow As Long
With Worksheets("sh")
  LastRow = .Cells(Rows.Count, "h").End(xlUp).Row
  Range("k:k,N:N,Q:Q,T:T,W:W,Z:Z,AC:AC,AF:AF,AI:AI" & LastRow).Select
  Selection.NumberFormat = "m/d/yyyy"
    Range("a1").Select
End With

    
End Sub
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
try this:
VBA Code:
Sub Macro1()
Dim LastRow As Long
Dim myrange As Range
With Worksheets("sh")
  LastRow = .Cells(Rows.Count, "h").End(xlUp).Row
  Set myrange = Union(.Range("k1:k" & LastRow), .Range("N1:N" & LastRow), .Range("Q1:Q" & LastRow))  ' add your other ragnes in like this
  myrange.NumberFormat = "m/d/yyyy"
    Range("a1").Select
End With

End Sub
 
Upvote 0
Hi,
try this update to your code & see if helps

VBA Code:
Sub Macro1()
    Dim LastRow As Long
    With Worksheets("sh")
      LastRow = .Cells(.Rows.Count, "h").End(xlUp).Row
        .Range("K1:K" & LastRow & ",N1:N" & LastRow & ",Q1:Q" & LastRow & _
               ",T1:T" & LastRow & ",W1:W" & LastRow & ",Z1:Z" & LastRow & _
               ",AC1:AC" & LastRow & ",AF1:AF" & LastRow & ",AI1:AI" & LastRow).NumberFormat = "m/d/yyyy"
    End With
    
End Sub

Dave
 
Upvote 0
Solution

Forum statistics

Threads
1,214,649
Messages
6,120,731
Members
448,987
Latest member
marion_davis

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